-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
59 lines (50 loc) · 1.85 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
pipeline {
agent any
environment {
TYK_DASH_URL = credentials('tyk-dash-url')
TYK_ORG_ID = credentials('tyk-org-id')
TYK_DASH_SECRET = credentials('tyk-dash-secret')
}
stages {
stage('test') {
steps {
script {
def apiDefs = findFiles(glob: 'api-*.json')
apiDefs.each { apiDef ->
def pJson = readJSON file: env.WORKSPACE + "/" + apiDef.name
println "Testing ${pJson.name}: ${pJson.api_id}"
println "ensuring api is authenticated"
assertAuthenticated(pJson)
println "ensuring api has appropriate tags"
assertWhitelistedTag(pJson)
}
}
}
}
stage('deploy') {
when {
expression { env.BRANCH_NAME == 'master' }
}
steps {
echo "Deploying, because we are on ${env.BRANCH_NAME}"
sh "wget https://github.com/davegarvey/tyk-jenkins-cicd-sync/releases/download/1.0.0/tyk-sync"
sh "chmod +x tyk-sync"
sh "./tyk-sync sync -d ${env.TYK_DASH_URL} -o ${env.TYK_ORG_ID} -s ${env.TYK_DASH_SECRET} ${env.WORKSPACE}/.git -b refs/heads/${env.BRANCH_NAME}"
}
}
}
post {
always {
deleteDir()
}
}
}
def static assertAuthenticated(api) {
assert api.use_keyless == false : "api ${api.name} should have authentication enabled"
}
def static assertWhitelistedTag(api) {
assert api.tags.size() > 0 : "api ${api.name} should be tagged either internal, external or both"
api.tags.each { tag ->
assert ["internal", "external"].contains(tag) : "api ${api.name} contains unknown tag ${tag}"
}
}