-
Notifications
You must be signed in to change notification settings - Fork 59
/
get-sources-rhpkg-container-build_3.17.jenkinsfile
226 lines (211 loc) · 11.8 KB
/
get-sources-rhpkg-container-build_3.17.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
#!/usr/bin/env groovy
import groovy.transform.Field
import groovy.json.JsonSlurper
// PARAMETERS for this pipeline:
// MIDSTM_BRANCH
// DWNSTM_BRANCH
// GIT_PATHs
// QUAY_REPO_PATHs
// UPDATE_BASE_IMAGES_FLAGS
// FLOATING_QUAY_TAGS
// SCRATCH
// FORCE_BUILD
// CLEAN_ON_FAILURE = "true"
@Field String NEW_TAG = ""
// NOTE: if rpm install in docker build problems reoccur, see CRW-1958
def String nodeLabel = 'x86_64-rhel8||ppc64le-rhel8'
currentBuild.description="Building " + QUAY_REPO_PATHs + "... "
timeout(360) {
node(nodeLabel) {
stage ("Build on ${nodeLabel}") {
wrap([$class: 'TimestamperBuildWrapper']) {
currentBuild.description=QUAY_REPO_PATHs.replaceAll("devspaces-3-rhel8-","").replaceAll("-rhel8","").trim() + "... "
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"
JOB_BRANCH = util.getJobBranch(MIDSTM_BRANCH)
DS_VERSION = util.getDsVersion(MIDSTM_BRANCH)
CSV_VERSION = util.getCSVVersion(MIDSTM_BRANCH)
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})))
}
util.cloneRepo("ssh://devspaces-build@pkgs.devel.redhat.com/${GIT_PATHs}", "sources", (util.globalVar({DWNSTM_BRANCH}) ? util.globalVar({DWNSTM_BRANCH}) : MIDSTM_BRANCH), false)
currentBuild.description=QUAY_REPO_PATHs.replaceAll("devspaces-3-rhel8-","").replaceAll("-rhel8","").trim() + " : ${JOB_BRANCH}"
try {
util.updateBaseImages("${WORKSPACE}/sources", (util.globalVar({DWNSTM_BRANCH}) ? util.globalVar({DWNSTM_BRANCH}) : MIDSTM_BRANCH), util.globalVar({UPDATE_BASE_IMAGES_FLAGS}))
sh('curl -sSLO https://raw.githubusercontent.com/redhat-developer/devspaces/'+ MIDSTM_BRANCH + '/product/rhpkg-container-build.sh && chmod +x rhpkg-container-build.sh')
echo "[INFO] Attempt to run rhpkg-container-build.sh, with up to 2 retries"
retry(2) {
// TODO CRW-3080 remove node env invocation here, if/when no longer needed (?)
sh('''#!/bin/bash
. ~/node_env ''' + DS_VERSION + '''
echo "Node: $(node --version) ( $(which node) )"
echo "Yarn: $(yarn --version) ( $(which yarn) )"
set -x
./rhpkg-container-build.sh ''' + CSV_VERSION +
(SCRATCH.equals("true") || SCRATCH == true ? " --scratch -d " + DWNSTM_BRANCH : "") +
''' -s ${WORKSPACE}/sources | tee ${WORKSPACE}/rhpkg-container-build.txt
''')
}
// compute BUILD_RESULT from output of rhpkg-container-build.sh, after BUILD_RESULT=
BUILD_RESULT=sh(returnStdout:true,script:'''sed -n '/BUILD_RESULT=/{:loop;n;p;b loop;}' ${WORKSPACE}/rhpkg-container-build.txt''').trim()
// compute the new tag (eg., 3.y-zz)
NEW_TAG=sh(returnStdout:true,script:'''grep --text 'TAGs=' ${WORKSPACE}/rhpkg-container-build.txt | sed -r -e "s#TAGs=##"''').trim()
// Task info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=33850006
TASK_URL=sh(returnStdout:true,script:'''grep --text 'TASK_URL=' ${WORKSPACE}/rhpkg-container-build.txt | sed -r -e "s#TASK_URL=##"''').trim()
BUILD_DESC=sh(returnStdout:true,script:'''grep --text 'BUILD_DESC=' ${WORKSPACE}/rhpkg-container-build.txt | sed -r -e "s#BUILD_DESC=##"''').trim()
if (util.hasSuccessfullyBuiltAllArches("${WORKSPACE}/sources/container.yaml", "${WORKSPACE}/rhpkg-container-build.txt")) {
currentBuild.result = "SUCCESS"
} else {
if (BUILD_DESC.indexOf("UNKNOWN")>=0) {
currentBuild.result = "UNSTABLE"
}
if (BUILD_RESULT.indexOf("ERROR")>=0 || BUILD_RESULT.indexOf("FAILURE")>=0 || !TASK_URL?.trim()) {
currentBuild.result = "FAILURE"
}
}
// CRW-2978 exceptions for non-standard links to operator and bundle
currentBuild.description+=" :: " +
BUILD_DESC.replaceAll("devspaces-3-rhel-9-operator-bundle","devspaces-operator-bundle").replaceAll("devspaces-3-rhel-9-operator","devspaces-rhel8-operator") +
" <br/> " + BUILD_RESULT
} catch (e) {
currentBuild.result = "FAILURE"
util.notifyBuildFailed(currentBuild.description)
throw e
} // try to build containers
// trigger simple copy to quay / UNSTABLE if fails
try {
// if build has passed, trigger a copy to quay
if (!currentBuild.result.equals("ABORTED") &&
!currentBuild.result.equals("FAILURE") &&
!currentBuild.result.equals("UNSTABLE")) {
sh ('curl -sSLO https://raw.githubusercontent.com/redhat-developer/devspaces/'+MIDSTM_BRANCH+'/product/getLatestImageTags.sh && chmod +x getLatestImageTags.sh')
CONTAINERS=QUAY_REPO_PATHs.trim()
withCredentials([string(credentialsId: 'quay.io-devspacesci_user_token', variable: 'QUAY_TOKEN_devspaces')]) {
// CRW-3463 can use podman login --tls-verify=false to work around 'certificate signed by unknown authority'
sh(script: '''#!/bin/bash -xe
echo "${QUAY_TOKEN_devspaces}" | podman login --authfile=~/.docker/config.json -u="devspaces+devspacesci" --password-stdin quay.io
echo " ########################################### "
echo " Copy latest images in osbs to quay: ''' + CONTAINERS + '''"
echo " ########################################### "
for c in ''' + CONTAINERS + '''; do
d=${c}
# special case for operator and bundle; all other images follow the pattern
# registry-proxy.engineering.redhat.com/rh-osbs/devspaces-operator:3.1-24
# registry-proxy.engineering.redhat.com/rh-osbs/devspaces-operator-bundle:3.1-155
if [[ $c == *"operator-bundle" ]]; then
d=operator-bundle
elif [[ $c == *"operator" ]]; then
d=operator
fi
./getLatestImageTags.sh -b ''' + MIDSTM_BRANCH + ''' -c devspaces-${d} --osbs --pushtoquay="''' + DS_VERSION + ''' ''' + FLOATING_QUAY_TAGS + '''" &
done
wait
''', returnStatus: true)
}
}
currentBuild.description+="; copied to quay"
} catch (e) {
currentBuild.result = "UNSTABLE"
currentBuild.description+="; <b style='color:red'>failed to copy to quay with getLatestImageTags.sh --pushtoquay</b>"
} // try
// trigger push-latest-container-to-quay job (does more than just copy to quay)
jobPath='/job/DS_CI/job/push-latest-container-to-quay_' + JOB_BRANCH
try {
CONTAINERS=QUAY_REPO_PATHs.trim()
println "########################################################################################################"
println "## Copy latest ${CONTAINERS} in OSBS to Quay"
println "########################################################################################################"
echo "currentBuild.result = " + currentBuild.result
if (!currentBuild.result.equals("ABORTED") &&
!currentBuild.result.equals("FAILURE") &&
!SCRATCH.equals("true") && SCRATCH!=true &&
QUAY_REPO_PATHs?.trim() && NEW_TAG?.trim()) {
final jobResult = build(
job: jobPath.replaceAll("/job/","/"),
// DO NOT propagate status here as we could get misleading results (eg., unstable = problem in the push-latest-container-to-quay)
// push-latest job now includes searching for IIBs (which can take a while) and
// creating multi-arch IIBs (which can take a while); may want to set wait: false to avoid timeouts
// or can increase/disable timeouts in downstream job
wait: true,
propagate: false,
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: "push+latest+${CONTAINERS}+to+quay"
],
[
$class: 'StringParameterValue',
name: 'CONTAINERS',
value: CONTAINERS
],
[
$class: 'StringParameterValue',
name: 'FLOATING_QUAY_TAGS',
value: FLOATING_QUAY_TAGS
],
[
$class: 'BooleanParameterValue',
name: 'CLEAN_ON_FAILURE',
value: CLEAN_ON_FAILURE
]
]
)
// if wait = true, can get a link to the downstream build
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"
// if wait == false, can only get a link to the downstream job (no build #)
// println("triggered build(" + jobPath + ") [no wait]")
// println("=?> Job ${JENKINS_URL}${jobPath} triggered.")
// currentBuild.description+="; <a href=${jobPath}/>" + jobPath + "</a> triggered"
}
} catch (e) {
currentBuild.result = "UNSTABLE"
currentBuild.description+="; <b style='color:orange'>Warning: <a href=${jobPath}/>" + (jobPath.replaceAll("/job/","/")) + "</a></b>"
} // try push-latest-container-to-quay job trigger
// collect related images for operator-bundle:NEW_TAG, and make them into HTML links
if (NEW_TAG?.trim() && QUAY_REPO_PATHs.contains("operator-bundle")){
currentBuild.description+=";<br />" +
"<blockquote>" +
"Bundle <a href=https://github.com/redhat-developer/devspaces-images/blob/" + MIDSTM_BRANCH + "/devspaces-operator-bundle-generated/manifests/devspaces.csv.yaml>CSV</a> related images:" +
sh(returnStdout:true, script:'''
curl -sSLO https://raw.githubusercontent.com/redhat-developer/devspaces/''' + MIDSTM_BRANCH + '''/product/checkImagesInCSV.sh && chmod +x checkImagesInCSV.sh
./checkImagesInCSV.sh registry-proxy.engineering.redhat.com/rh-osbs/devspaces-operator-bundle:'''+NEW_TAG+''' --quay -qq
''').trim().replaceAll("(quay.io.+)","<br />- <a href='https://\$1'>\$1</a>").replaceAll("(registry.redhat.io/([^/]+/[^/]+):.+)","<br />= <a href='https://catalog.redhat.com/software/containers/search?q=\$2'>\$1</a>") +
"</blockquote>"
}
// 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})))
}
} // withCreds
} // wrap
cleanWs(
cleanWhenSuccess: true,
cleanWhenUnstable: true,
cleanWhenNotBuilt: false,
cleanWhenFailure: CLEAN_ON_FAILURE,
cleanWhenAborted: true,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true
)
} // stage
} //node
} // timeout