-
Notifications
You must be signed in to change notification settings - Fork 59
/
update-digests_3.16.jenkinsfile
216 lines (193 loc) · 11.2 KB
/
update-digests_3.16.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
#!/usr/bin/env groovy
import groovy.transform.Field
// PARAMETERS for this pipeline:
// MIDSTM_BRANCH
// CLEAN_ON_FAILURE = "true"
def errorOccurred = false
def String nodeLabel = 'x86_64-rhel8||ppc64le-rhel8'
timeout(240) {
node(nodeLabel){
try {
stage ("Check for updated images") {
wrap([$class: 'TimestamperBuildWrapper']) {
withCredentials([string(credentialsId:'crw_devstudio-release-token', variable: 'GITHUB_TOKEN')]) {
sh('curl -sSLO https://raw.githubusercontent.com/redhat-developer/devspaces/'+ MIDSTM_BRANCH + '/product/util2.groovy')
def util = load "${WORKSPACE}/util2.groovy"
cleanWs()
// comment on the PR with links to this job
if (util.globalVar({comments_url})?.trim()) {
println("Used PR comment URL: " + util.commentOnPullRequestBuildLinks(util.globalVar({comments_url})))
}
DS_VERSION = util.getDsVersion(MIDSTM_BRANCH)
println "DS_VERSION = '" + DS_VERSION + "'"
JOB_BRANCH = util.getJobBranch(MIDSTM_BRANCH)
util.cloneRepo("https://github.com/redhat-developer/devspaces.git", "devspaces", MIDSTM_BRANCH, false)
def NEW_IMAGES = sh (
script: "cd ${WORKSPACE}/devspaces/product && ./getLatestImageTags.sh -b ${MIDSTM_BRANCH} --quay --tag ${DS_VERSION} --hide | tee ${WORKSPACE}/devspaces/dependencies/LATEST_IMAGES.new",
returnStdout: true
).trim().split()
// check for Quay outage
if (NEW_IMAGES.toString().indexOf("No tags matching")>-1)
{
errorOccurred = true
error('Missing tags when reading from quay.io: may be experiencing an outage. Abort!')
currentBuild.result = 'ABORTED'
}
echo "------"
def CURRENT_IMAGES = sh (
script: 'cat ${WORKSPACE}/devspaces/dependencies/LATEST_IMAGES',
returnStdout: true
).trim().split()
sh '''#!/bin/bash -xe
cp ${WORKSPACE}/devspaces/dependencies/LATEST_IMAGES{,.prev}
echo "============ LATEST_IMAGES.prev ============>"
cat ${WORKSPACE}/devspaces/dependencies/LATEST_IMAGES.prev
echo "<============ LATEST_IMAGES ============"
NUM_IMAGES=$(cat ${WORKSPACE}/devspaces/dependencies/LATEST_IMAGES.prev | wc -l)
if [[ NUM_IMAGES -lt 1 ]]; then
echo "ERROR: dependencies/LATEST_IMAGES.prev file is empty!"
exit 1
else
echo "Found $NUM_IMAGES images in dependencies/LATEST_IMAGES.prev"
fi
'''
// compare new and curent images
def newSet = NEW_IMAGES as Set
// def currentSet = CURRENT_IMAGES as Set
def operatorBundleImage = newSet.find { it.contains("operator-bundle") }
// newSet.each { echo "New: $it" }
// currentSet.each { echo "Current: $it" }
sh '''#!/bin/bash -xe
echo "============ LATEST_IMAGES.new 1 ============>"
cat ${WORKSPACE}/devspaces/dependencies/LATEST_IMAGES.new
echo "<============ LATEST_IMAGES.new 1 ============"
NUM_IMAGES=$(cat ${WORKSPACE}/devspaces/dependencies/LATEST_IMAGES.new | wc -l)
if [[ NUM_IMAGES -lt 1 ]]; then
echo "ERROR: dependencies/LATEST_IMAGES.new file is empty!"
exit 1
else
echo "Found $NUM_IMAGES images in dependencies/LATEST_IMAGES.new"
fi
'''
// don't report a diff when new operator-bundle, or we'll never get out of this recursion loop; instead report new images (anything that will cause a new bundle image to be rebuilt)
def DIFF_LATEST_IMAGES_ANY_BUT_BUNDLE = sh (script: '''
diff -u0 ${WORKSPACE}/devspaces/dependencies/LATEST_IMAGES.{prev,new} | \
grep -E -v "@@|dependencies/LATEST_IMAGES|operator-bundle" | \
sed -r -e "s@quay.io/devspaces/|:.+|-rhel8|\\n|\\r|^(-|\\+)@@g" | sort -uV || true
''', returnStdout: true).trim()
// check diff including operator bundle, in case we forgot to update
def DIFF_LATEST_IMAGES_BUNDLE_ONLY = sh (script: '''
diff -u0 ${WORKSPACE}/devspaces/dependencies/LATEST_IMAGES.{prev,new} | \
grep -E -v "@@|dependencies/LATEST_IMAGES" | grep -E "operator-bundle" | \
sed -r -e "s@quay.io/devspaces/|:.+|-rhel8|\\n|\\r|^(-|\\+)@@g" | sort -uV || true
''', returnStdout: true).trim()
// define what to do when we are ready to push changes
def COMMITCHANGES = '''#!/bin/bash -xe
pushd ${WORKSPACE}/devspaces >/dev/null
# clean up unneeded files
rm -f ./dependencies/LATEST_IMAGES{.new,.prev}
# regenerate LATEST_IMAGES, LATEST_IMAGES_COMMITS, and LATEST_IMAGES_DIGESTS.json
./dependencies/LATEST_IMAGES.sh --commit
echo "============ LATEST_IMAGES new 2 ============>"
cat dependencies/LATEST_IMAGES
echo "<============ LATEST_IMAGES new 2 ============"
popd >/dev/null
'''
currentBuild.description="Checking for changed images..."
if (!DIFF_LATEST_IMAGES_BUNDLE_ONLY.equals("") && DIFF_LATEST_IMAGES_ANY_BUT_BUNDLE.equals("")) {
// no changes, but a newer bundle image exists
currentBuild.description="New bundle image detected: commit changes to LATEST_IMAGES"
echo currentBuild.description
echo DIFF_LATEST_IMAGES_BUNDLE_ONLY
sh COMMITCHANGES
currentBuild.result='UNSTABLE'
} else if (DIFF_LATEST_IMAGES_ANY_BUT_BUNDLE.equals("")) {
// no changes
currentBuild.description="No new images detected: nothing to do!"
echo currentBuild.description
currentBuild.result='UNSTABLE'
} else {
currentBuild.description="Detected new images: rebuild operator-bundle<br/>* " + DIFF_LATEST_IMAGES_ANY_BUT_BUNDLE.replaceAll('\n',"<br/>* ")
echo currentBuild.description
echo DIFF_LATEST_IMAGES_ANY_BUT_BUNDLE
jobPath='/job/DS_CI/job/operator-bundle_' + JOB_BRANCH
final jobResult = build(
job: jobPath.replaceAll("/job/","/"),
wait: true,
propagate: true,
quietPeriod: 0,
parameters: [
[
$class: 'StringParameterValue',
name: 'comments_url',
value: util.globalVar({comments_url})
],
[
$class: 'StringParameterValue',
name: 'token',
value: "CI_BUILD"
],
[
$class: 'StringParameterValue',
name: 'cause',
value: "update+digests+for+"+DIFF_LATEST_IMAGES_ANY_BUT_BUNDLE.replaceAll("\n", "+").replaceAll(" ", "+")
],
[
$class: 'BooleanParameterValue',
name: 'FORCE_BUILD',
value: true
]
]
)
jobLink=jobPath + "/" + jobResult?.number?.toString()
println("waiting for build(" + jobPath + ")")
println("++> Job ${JENKINS_URL}${jobLink}/console completed.")
currentBuild.description+="; <a href=${jobLink}/>" + (jobLink.replaceAll("/job/","/")) + "</a> triggered"
while (true)
{
def rebuiltOperatorBundleImage = sh (
script: "cd ${WORKSPACE}/devspaces/product && ./getLatestImageTags.sh -b ${MIDSTM_BRANCH} -c 'devspaces/devspaces-operator-bundle' --quay --tag ${DS_VERSION} --hide",
returnStdout: true
).trim()
println "${rebuiltOperatorBundleImage}"
if (rebuiltOperatorBundleImage!=operatorBundleImage) {
println "Operator bundle has been rebuilt!"
break
}
sleep(time:120,unit:"SECONDS")
}
sh COMMITCHANGES
}
// comment on the PR with this job's build description
if (util.globalVar({comments_url})?.trim()) {
println("Used PR comment URL: " + util.commentOnPullRequestBuildDescription(util.globalVar({comments_url})))
}
} // with
} // wrap
cleanWs(
cleanWhenSuccess: true,
cleanWhenUnstable: true,
cleanWhenNotBuilt: false,
cleanWhenFailure: CLEAN_ON_FAILURE,
cleanWhenAborted: true,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true
)
} // stage
} catch (e) {
if (errorOccurred) {
withCredentials([string(credentialsId:'crw_devstudio-release-token', variable: 'GITHUB_TOKEN')]) {
sh('curl -sSLO https://raw.githubusercontent.com/redhat-developer/devspaces/'+ MIDSTM_BRANCH + '/product/util2.groovy')
def util = load "${WORKSPACE}/util2.groovy"
if (util.globalVar({comments_url})?.trim()) {
println("Used PR comment URL: " + util.commentOnPullRequestBuildDescription(util.globalVar({comments_url})))
}
util.notifyBuildFailed(currentBuild.description)
}
return
}
throw e
} // try-catch
} // node
} // timeout