-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
144 lines (141 loc) · 5.09 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!groovy
pipeline {
agent any
stages {
stage('FetchCode') {
steps {
dir('cdis-manifest') {
checkout scm
}
dir('gen3-qa') {
git(
url: 'https://github.com/uc-cdis/gen3-qa.git',
branch: 'master'
)
}
dir('cloud-automation') {
git(
url: 'https://github.com/uc-cdis/cloud-automation.git',
branch: 'master'
)
}
}
}
stage('DetectChanges') {
steps {
script {
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def affectedPaths = entries[j].getAffectedPaths()
env.ABORT_SUCCESS = 'false';
env.KUBECTL_NAMESPACE = 'qa-bloodpac'
if (affectedPaths.contains('nci-crdc.datacommons.io/manifest.json')) {
env.AFFECTED_PATH = 'nci-crdc.datacommons.io/manifest.json'
env.KUBECTL_NAMESPACE = 'default'
} else if (affectedPaths.contains('nci-crdc-staging.datacommons.io/manifest.json')) {
env.AFFECTED_PATH = 'nci-crdc-staging.datacommons.io/manifest.json'
env.KUBECTL_NAMESPACE = 'default'
} else if (affectedPaths.contains('nci-crdc-demo.datacommons.io/manifest.json')) {
env.AFFECTED_PATH = 'nci-crdc-demo.datacommons.io/manifest.json'
env.KUBECTL_NAMESPACE = 'default'
} else if (affectedPaths.contains('data.bloodpac.org/manifest.json')) {
env.AFFECTED_PATH = 'data.bloodpac.org/manifest.json'
} else if (affectedPaths.contains('data.braincommons.org/manifest.json')) {
env.AFFECTED_PATH = 'data.braincommons.org/manifest.json'
env.KUBECTL_NAMESPACE = 'qa-brain'
} else if (affectedPaths.contains('data.kidsfirstdrc.org/manifest.json')) {
env.AFFECTED_PATH = 'data.kidsfirstdrc.org/manifest.json'
env.KUBECTL_NAMESPACE = 'qa-kidsfirst'
} else if (affectedPaths.contains('niaid.bionimbus.org/manifest.json')) {
env.AFFECTED_PATH = 'niaid.bionimbus.org/manifest.json'
env.KUBECTL_NAMESPACE = 'qa-niaid'
} else if (affectedPaths.contains('dcp.bionimbus.org/manifest.json')) {
env.AFFECTED_PATH = 'dcp.bionimbus.org/manifest.json'
env.KUBECTL_NAMESPACE = 'qa-dcp'
} else {
println "production stuff was not affected, aborting"
currentBuild.result = 'SUCCESS'
env.ABORT_SUCCESS = 'true';
}
}
}
}
}
}
stage('SubstituteManifest') {
when {
environment name: 'ABORT_SUCCESS', value: 'false'
}
steps {
script {
dirname = sh(script: "kubectl -n $env.KUBECTL_NAMESPACE get configmap global -o jsonpath='{.data.hostname}'", returnStdout: true)
}
dir('cdis-manifest') {
withEnv(["fromPath=$env.AFFECTED_PATH", "toPath=$dirname/manifest.json"]) {
sh "cp $env.fromPath $env.toPath"
}
}
}
}
stage('K8sDeploy') {
when {
environment name: 'ABORT_SUCCESS', value: 'false'
}
steps {
withEnv(['GEN3_NOPROXY=true', "vpc_name=$env.KUBECTL_NAMESPACE", "GEN3_HOME=$env.WORKSPACE/cloud-automation"]) {
echo "GEN3_HOME is $env.GEN3_HOME"
echo "GIT_BRANCH is $env.GIT_BRANCH"
echo "GIT_COMMIT is $env.GIT_COMMIT"
echo "KUBECTL_NAMESPACE is $env.KUBECTL_NAMESPACE"
echo "WORKSPACE is $env.WORKSPACE"
sh "bash cloud-automation/gen3/bin/kube-roll-all.sh"
sh "bash cloud-automation/gen3/bin/kube-wait4-pods.sh || true"
}
}
}
stage('RunInstall') {
when {
environment name: 'ABORT_SUCCESS', value: 'false'
}
steps {
dir('gen3-qa') {
withEnv(['GEN3_NOPROXY=true']) {
sh "bash ./run-install.sh"
}
}
}
}
stage('RunTests') {
when {
environment name: 'ABORT_SUCCESS', value: 'false'
}
steps {
dir('gen3-qa') {
withEnv(['GEN3_NOPROXY=true', "vpc_name=$env.KUBECTL_NAMESPACE", "GEN3_HOME=$env.WORKSPACE/cloud-automation"]) {
sh "bash ./run-tests.sh $env.KUBECTL_NAMESPACE"
}
}
}
}
}
post {
success {
echo "https://jenkins.planx-pla.net/ $env.JOB_NAME pipeline succeeded"
}
failure {
echo "Failure!"
archiveArtifacts artifacts: '**/output/*.png', fingerprint: true
junit "gen3-qa/output/*.xml"
//slackSend color: 'bad', message: "https://jenkins.planx-pla.net $env.JOB_NAME pipeline failed"
}
unstable {
echo "Unstable!"
//slackSend color: 'bad', message: "https://jenkins.planx-pla.net $env.JOB_NAME pipeline unstable"
}
always {
echo "done"
}
}
}