forked from kiali/kiali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
280 lines (263 loc) · 11.3 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
* The Jenkins job should be configured with the following properties:
*
* - Disable concurrent builds
* - Parameters (all must be trimmed; all are strings):
* - RELEASE_TYPE
* defaultValue: auto
* description: Valid values are: auto, minor, snapshot.0, snapshot.1, edge. When "auto" is
* specified, the type of the release will be determined based on the current date.
* - RELEASING_BRANCHES
* defaultValue: refs/heads/master
* description: Name of branch of all repositories to checkout and run the release. The only
* exception is the website which is always run on the `master` branch.
* - BACKEND_REPO
* defaultValue: kiali/kiali
* description: The GitHub repo of the back-end sources, in owner/repo format.
* - UI_REPO
* defaultValue: kiali/kiali-ui
* description: The GitHub repo of the front-end sources, in owner/repo format.
* - OPERATOR_REPO
* defaultValue: kiali/kiali-operator
* description: The GitHub repo of the kiali-operator sources, in owner/repo format.
* - SITE_REPO
* defaultValue: kiali/kiali.io
* description: The GitHub repo of the website sources, in owner/repo format.
* - HELM_REPO
* defaultValue: kiali/helm-charts
* description: The GitHub repo of the Helm charts sources, in owner/repo format.
* - QUAY_NAME
* defaultValue: quay.io/kiali/kiali
* description: The name of the Quay repository to push the release
* - QUAY_OPERATOR_NAME
* defaultValue: quay.io/kiali/kiali-operator
* description: The name of the Quay repository to push the operator release
* - NPM_DRY_RUN
* defaultValue: n
* description: Set to "y" if you want to make a "dry run" of the front-end release process
* - SKIP_BACKEND_RELEASE
* defaultValue: n
* description: Set to 'y' if you don't want to release the backend
* - SKIP_UI_RELEASE
* defaultValue: n
* description: Set to 'y' if you don't want to release the UI
* - SKIP_OPERATOR_RELEASE
* defaultValue: n
* description: Set to 'y' if you don't want to release the operator
* - SKIP_HELM_RELEASE
* defaultValue: n
* description: Set to 'y' if you don't want to release the helm charts
* - SKIP_SITE_RELEASE
* defaultValue: n
* description: Set to 'y' if you don't want to release the website
* - UI_VERSION
* defaultValue: ''
* description: If you are skipping UI release. Specify the UI version to package, or leave
* unset to use the version present in the main Makefile (e.g. leave unset for patch releases)
* - NPM_CONFIG_REGISTRY
* defaultValue: ''
* description: NPM registry to use for fetching packages. This is not used for publishing releases.
* Do not include the trailing slash.
* - NOTIFICATIONS_EMAIL
* defaultValue: ''
* description: E-mail for sending build failure notifications.
*/
node('kiali-build && fedora') {
def backendDir = 'src/github.com/kiali/kiali'
def backendMakefile = 'deploy/jenkins-ci/Makefile'
def uiDir = 'src/github.com/kiali/kiali-ui'
def uiMakefile = 'Makefile.jenkins'
def buildUi = params.SKIP_UI_RELEASE != "y"
def buildBackend = params.SKIP_BACKEND_RELEASE != "y"
def buildOperator = params.SKIP_OPERATOR_RELEASE != "y"
def buildHelm = params.SKIP_HELM_RELEASE != "y" // Temptative value. It's re-assigned later.
def buildSite = params.SKIP_SITE_RELEASE != "y" // Temptative value. It's re-assigned later.
def quayTag = ""
if ( !buildBackend && !buildUi && !buildOperator && !buildHelm && !buildSite ) {
currentBuild.result = 'ABORTED'
echo "Nothing to release. Stopping."
return
}
try {
cleanWs()
stage('Checkout code') {
if ( buildBackend || buildOperator || buildHelm || buildSite ) {
checkout([
$class: 'GitSCM',
branches: [[name: params.RELEASING_BRANCHES]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'RelativeTargetDirectory', relativeTargetDir: backendDir]
],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'kiali-bot-gh-ssh',
url: "[email protected]:${params.BACKEND_REPO}.git"]]
])
sh "cd ${backendDir}; git config user.email '[email protected]'"
sh "cd ${backendDir}; git config user.name 'kiali-bot'"
}
if ( buildUi ) {
checkout([
$class: 'GitSCM',
branches: [[name: params.RELEASING_BRANCHES]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'RelativeTargetDirectory', relativeTargetDir: uiDir]
],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'kiali-bot-gh-ssh',
url: "[email protected]:${params.UI_REPO}.git"]]
])
sh "cd ${uiDir}; git config user.email '[email protected]'"
sh "cd ${uiDir}; git config user.name 'kiali-bot'"
}
}
// Determine release type if "auto" was specified
def releaseType = "${params.RELEASE_TYPE}"
if ( releaseType == "auto" ) {
releaseType = sh(
returnStdout: true,
script: "${backendDir}/deploy/jenkins-ci/bin/determine-release-type.sh").trim()
}
buildSite = params.SKIP_SITE_RELEASE != "y" && releaseType == "minor"
buildHelm = params.SKIP_HELM_RELEASE != "y" && (releaseType == "minor" || releaseType == "patch")
echo "Resolved release type: ${releaseType}"
echo "Will build back-end? ${buildBackend}"
echo "Will build front-end? ${buildUi}"
echo "Will build operator? ${buildOperator}"
echo "Will build Helm charts? ${buildHelm}"
echo "Will build site? ${buildSite}"
withEnv(["PATH+TOOLS=${env.WORKSPACE}/${backendDir}/deploy/jenkins-ci/bin",
"GOPATH=${env.WORKSPACE}",
"[email protected]:${params.BACKEND_REPO}.git",
"[email protected]:kiali-bot/kiali.git",
"BACKEND_PULL_URI=https://api.github.com/repos/${params.BACKEND_REPO}/pulls",
"[email protected]:${params.UI_REPO}.git",
"[email protected]:kiali-bot/kiali-ui.git",
"UI_PULL_URI=https://api.github.com/repos/${params.UI_REPO}/pulls",
"RELEASE_TYPE=${releaseType}"
]) {
parallel backend: {
withEnv(["GOPATH=${env.WORKSPACE}"]) {
stage('Build backend') {
if ( buildBackend ) {
sh "make -f ${backendMakefile} -C ${backendDir} backend-build-release"
}
}
stage('Test backend') {
if ( buildBackend ) {
sh "make -f ${backendMakefile} -C ${backendDir} backend-test"
}
}
}
}, ui: {
stage('Build UI') {
if ( buildUi ) {
sh "make -f ${uiMakefile} -C ${uiDir} ui-fix-version ui-build"
}
}
stage('Test UI') {
if ( buildUi ) {
sh "make -f ${uiMakefile} -C ${uiDir} ui-test"
}
}
},
failFast: true
stage('Release kiali-ui to NPM') {
if ( buildUi ) {
withCredentials([string(credentialsId: 'kiali-npm', variable: 'NPM_TOKEN')]) {
sh "make -f ${uiMakefile} -C ${uiDir} ui-npm-publish"
}
}
}
stage('Create release cut in front-end repo') {
if ( buildUi ) {
withCredentials([string(credentialsId: 'kiali-bot-gh-token', variable: 'GH_TOKEN')]) {
sshagent(['kiali-bot-gh-ssh']) {
sh "make -f ${uiMakefile} -C ${uiDir} ui-push-version-tag ui-prepare-next-version"
}
}
}
}
stage('Release Kiali to Container Repositories') {
if ( buildBackend ) {
withCredentials([usernamePassword(credentialsId: 'kiali-quay', passwordVariable: 'QUAY_PASSWORD', usernameVariable: 'QUAY_USER')]) {
sh "make -f ${backendMakefile} -C ${backendDir} backend-push-docker"
quayTag = sh(returnStdout: true, script: "sed -rn 's/^VERSION \\?= v(.*)/v\\1/p' ${backendDir}/Makefile").trim()
}
}
}
stage('Create release cut in back-end repo') {
if ( buildBackend ) {
withCredentials([string(credentialsId: 'kiali-bot-gh-token', variable: 'GH_TOKEN')]) {
sshagent(['kiali-bot-gh-ssh']) {
sh "make -f ${backendMakefile} -C ${backendDir} backend-push-version-tag backend-prepare-next-version"
}
}
}
}
stage('Invoke other jobs') {
if ( buildOperator ) {
build(job: 'kiali-operator-release',
parameters: [
[$class: 'StringParameterValue', value: releaseType, name: 'RELEASE_TYPE'],
[$class: 'StringParameterValue', value: params.OPERATOR_REPO, name: 'OPERATOR_REPO'],
[$class: 'StringParameterValue', value: params.RELEASING_BRANCHES, name: 'OPERATOR_RELEASING_BRANCH'],
[$class: 'StringParameterValue', value: params.QUAY_OPERATOR_NAME, name: 'QUAY_OPERATOR_NAME']
], wait: false
)
}
if ( buildSite ) {
// Although the `kiali-website-release` can receive the "releasing branch",
// don't pass it and let it use the default `refs/heads/master`. It's unused at the moment.
// The website is "released" only on minor and major releases and it's only tagged. No "version branch"
// is created. This is because versioned docs are simple folders within the repository
// that are in the `master` branch. So, if a previous version of the doc needs to be
// updated, that's done manually. Docs tend to not change for patch releases and also
// tend to be fixed regardless if there is (or not) a patch release.
build(job: 'kiali-website-release',
parameters: [
[$class: 'StringParameterValue', value: params.SITE_REPO, name: 'SITE_REPO']
], wait: false
)
}
if ( buildHelm ) {
build(job: 'kiali-helm-release',
parameters: [
[$class: 'StringParameterValue', value: releaseType, name: 'RELEASE_TYPE'],
[$class: 'StringParameterValue', value: params.HELM_REPO, name: 'HELM_REPO'],
[$class: 'StringParameterValue', value: params.RELEASING_BRANCHES, name: 'HELM_RELEASING_BRANCH']
], wait: false
)
}
}
stage('Post Msg Bus Notification') {
if ( releaseType == "minor" ) {
build(job: 'kiali-release-notifier',
parameters: [
[$class: 'StringParameterValue', value: 'minor', name: 'RELEASE_TYPE'],
[$class: 'StringParameterValue', value: "${params.QUAY_NAME}", name: 'QUAY_NAME'],
[$class: 'StringParameterValue', value: quayTag, name: 'QUAY_TAG']
], wait: false
)
}
}
}
} catch (e) {
echo e.toString()
if (params.NOTIFICATIONS_EMAIL.length() != 0) {
emailext(
to: params.NOTIFICATIONS_EMAIL,
subject: 'Kiali build failure',
body: '${JELLY_SCRIPT,template="html"}',
attachLog: true,
mimeType: 'text/html'
)
}
throw e
} finally {
cleanWs()
}
}