Skip to content

Commit 97c88c9

Browse files
HADOOP-17807. Use separate src dir for platform builds (#3210)
1 parent d710ec8 commit 97c88c9

File tree

2 files changed

+194
-69
lines changed

2 files changed

+194
-69
lines changed

dev-support/Jenkinsfile

Lines changed: 139 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ pipeline {
2929
}
3030

3131
environment {
32-
SOURCEDIR = 'src'
33-
// will also need to change notification section below
34-
PATCHDIR = 'out'
3532
YETUS='yetus'
3633
// Branch or tag name. Yetus release tags are 'rel/X.Y.Z'
3734
YETUS_VERSION='f9ba0170a5787a5f4662d3769804fef0226a182f'
@@ -56,13 +53,44 @@ pipeline {
5653
}
5754
}
5855

56+
// Setup codebase so that each platform's build happens in its own exclusive copy of the
57+
// codebase.
58+
// Primarily because YETUS messes up the git branch information and affects the subsequent
59+
// optional stages after the first one.
60+
stage ('setup sources') {
61+
steps {
62+
dir("${WORKSPACE}/centos-8") {
63+
sh '''#!/usr/bin/env bash
64+
65+
cp -Rp ${WORKSPACE}/src ${WORKSPACE}/centos-8
66+
'''
67+
}
68+
69+
dir("${WORKSPACE}/debian-10") {
70+
sh '''#!/usr/bin/env bash
71+
72+
cp -Rp ${WORKSPACE}/src ${WORKSPACE}/debian-10
73+
'''
74+
}
75+
76+
dir("${WORKSPACE}/ubuntu-focal") {
77+
sh '''#!/usr/bin/env bash
78+
79+
cp -Rp ${WORKSPACE}/src ${WORKSPACE}/ubuntu-focal
80+
'''
81+
}
82+
}
83+
}
84+
5985
// This is an optional stage which runs only when there's a change in
6086
// C++/C++ build/platform.
6187
// This stage serves as a means of cross platform validation, which is
6288
// really needed to ensure that any C++ related/platform change doesn't
6389
// break the Hadoop build on Centos 8.
6490
stage ('precommit-run Centos 8') {
6591
environment {
92+
SOURCEDIR = "${WORKSPACE}/centos-8/src"
93+
PATCHDIR = "${WORKSPACE}/centos-8/out"
6694
DOCKERFILE = "${SOURCEDIR}/dev-support/docker/Dockerfile_centos_8"
6795
IS_OPTIONAL = 1
6896
}
@@ -78,10 +106,32 @@ pipeline {
78106
sh '''#!/usr/bin/env bash
79107
80108
chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
81-
"${SOURCEDIR}/dev-support/jenkins.sh"
109+
"${SOURCEDIR}/dev-support/jenkins.sh" run_ci
82110
'''
83111
}
84112
}
113+
114+
post {
115+
// Since this is an optional platform, we want to copy the artifacts
116+
// and archive it only if the build fails, to help with debugging.
117+
failure {
118+
sh '''#!/usr/bin/env bash
119+
120+
cp -Rp "${WORKSPACE}/centos-8/out" "${WORKSPACE}"
121+
'''
122+
archiveArtifacts "out/**"
123+
}
124+
125+
cleanup() {
126+
script {
127+
sh '''#!/usr/bin/env bash
128+
129+
chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
130+
"${SOURCEDIR}/dev-support/jenkins.sh" cleanup_ci_proc
131+
'''
132+
}
133+
}
134+
}
85135
}
86136

87137
// This is an optional stage which runs only when there's a change in
@@ -91,6 +141,8 @@ pipeline {
91141
// break the Hadoop build on Debian 10.
92142
stage ('precommit-run Debian 10') {
93143
environment {
144+
SOURCEDIR = "${WORKSPACE}/debian-10/src"
145+
PATCHDIR = "${WORKSPACE}/debian-10/out"
94146
DOCKERFILE = "${SOURCEDIR}/dev-support/docker/Dockerfile_debian_10"
95147
IS_OPTIONAL = 1
96148
}
@@ -106,16 +158,40 @@ pipeline {
106158
sh '''#!/usr/bin/env bash
107159
108160
chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
109-
"${SOURCEDIR}/dev-support/jenkins.sh"
161+
"${SOURCEDIR}/dev-support/jenkins.sh" run_ci
110162
'''
111163
}
112164
}
165+
166+
post {
167+
// Since this is an optional platform, we want to copy the artifacts
168+
// and archive it only if the build fails, to help with debugging.
169+
failure {
170+
sh '''#!/usr/bin/env bash
171+
172+
cp -Rp "${WORKSPACE}/debian-10/out" "${WORKSPACE}"
173+
'''
174+
archiveArtifacts "out/**"
175+
}
176+
177+
cleanup() {
178+
script {
179+
sh '''#!/usr/bin/env bash
180+
181+
chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
182+
"${SOURCEDIR}/dev-support/jenkins.sh" cleanup_ci_proc
183+
'''
184+
}
185+
}
186+
}
113187
}
114188

115189
// We want to use Ubuntu Focal as our main CI and thus, this stage
116190
// isn't optional (runs for all the PRs).
117191
stage ('precommit-run Ubuntu focal') {
118192
environment {
193+
SOURCEDIR = "${WORKSPACE}/ubuntu-focal/src"
194+
PATCHDIR = "${WORKSPACE}/ubuntu-focal/out"
119195
DOCKERFILE = "${SOURCEDIR}/dev-support/docker/Dockerfile"
120196
IS_OPTIONAL = 0
121197
}
@@ -131,69 +207,76 @@ pipeline {
131207
sh '''#!/usr/bin/env bash
132208
133209
chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
134-
"${SOURCEDIR}/dev-support/jenkins.sh"
210+
"${SOURCEDIR}/dev-support/jenkins.sh" run_ci
135211
'''
136212
}
137213
}
138-
}
139214

140-
}
215+
post {
216+
always {
217+
script {
218+
// Publish status if it was missed (YETUS-1059)
219+
withCredentials(
220+
[usernamePassword(credentialsId: '683f5dcf-5552-4b28-9fb1-6a6b77cf53dd',
221+
passwordVariable: 'GITHUB_TOKEN',
222+
usernameVariable: 'GITHUB_USER')]) {
223+
sh '''#!/usr/bin/env bash
141224
142-
post {
143-
always {
144-
script {
145-
// Publish status if it was missed (YETUS-1059)
146-
withCredentials(
147-
[usernamePassword(credentialsId: '683f5dcf-5552-4b28-9fb1-6a6b77cf53dd',
148-
passwordVariable: 'GITHUB_TOKEN',
149-
usernameVariable: 'GITHUB_USER')]) {
150-
sh '''#!/usr/bin/env bash
151-
YETUS_ARGS+=("--github-token=${GITHUB_TOKEN}")
152-
YETUS_ARGS+=("--patch-dir=${WORKSPACE}/${PATCHDIR}")
153-
TESTPATCHBIN="${WORKSPACE}/${YETUS}/precommit/src/main/shell/github-status-recovery.sh"
154-
/usr/bin/env bash "${TESTPATCHBIN}" "${YETUS_ARGS[@]}" ${EXTRA_ARGS} || true
155-
'''
156-
}
225+
# Copy the artifacts of Ubuntu focal build to workspace
226+
cp -Rp "${WORKSPACE}/ubuntu-focal/out" "${WORKSPACE}"
227+
228+
# Send Github status
229+
chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
230+
"${SOURCEDIR}/dev-support/jenkins.sh" github_status_recovery
231+
'''
232+
}
157233

158-
// Yetus output
159-
archiveArtifacts "${env.PATCHDIR}/**"
160-
// Publish the HTML report so that it can be looked at
161-
// Has to be relative to WORKSPACE.
162-
publishHTML (target: [
163-
allowMissing: true,
164-
keepAll: true,
165-
alwaysLinkToLastBuild: true,
166-
// Has to be relative to WORKSPACE
167-
reportDir: "${env.PATCHDIR}",
168-
reportFiles: 'report.html',
169-
reportName: 'Yetus Report'
170-
])
171-
// Publish JUnit results
172-
try {
173-
junit "${env.SOURCEDIR}/**/target/surefire-reports/*.xml"
174-
} catch(e) {
175-
echo 'junit processing: ' + e.toString()
234+
// YETUS output
235+
archiveArtifacts "out/**"
236+
237+
// Publish the HTML report so that it can be looked at
238+
// Has to be relative to WORKSPACE.
239+
publishHTML (target: [
240+
allowMissing: true,
241+
keepAll: true,
242+
alwaysLinkToLastBuild: true,
243+
// Has to be relative to WORKSPACE
244+
reportDir: "out",
245+
reportFiles: 'report.html',
246+
reportName: 'Yetus Report'
247+
])
248+
249+
// Publish JUnit results
250+
try {
251+
junit "${SOURCEDIR}/**/target/surefire-reports/*.xml"
252+
} catch(e) {
253+
echo 'junit processing: ' + e.toString()
254+
}
255+
}
256+
}
257+
258+
cleanup() {
259+
script {
260+
sh '''#!/usr/bin/env bash
261+
262+
chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
263+
"${SOURCEDIR}/dev-support/jenkins.sh" cleanup_ci_proc
264+
'''
265+
}
266+
}
176267
}
177-
}
178268
}
269+
}
179270

271+
post {
180272
// Jenkins pipeline jobs fill slaves on PRs without this :(
181273
cleanup() {
182274
script {
183-
sh '''
184-
# See YETUS-764
185-
if [ -f "${WORKSPACE}/${PATCHDIR}/pidfile.txt" ]; then
186-
echo "test-patch process appears to still be running: killing"
187-
kill `cat "${WORKSPACE}/${PATCHDIR}/pidfile.txt"` || true
188-
sleep 10
189-
fi
190-
if [ -f "${WORKSPACE}/${PATCHDIR}/cidfile.txt" ]; then
191-
echo "test-patch container appears to still be running: killing"
192-
docker kill `cat "${WORKSPACE}/${PATCHDIR}/cidfile.txt"` || true
193-
fi
194-
# See HADOOP-13951
195-
chmod -R u+rxw "${WORKSPACE}"
196-
'''
275+
sh '''#!/usr/bin/env bash
276+
277+
# See HADOOP-13951
278+
chmod -R u+rxw "${WORKSPACE}"
279+
'''
197280
deleteDir()
198281
}
199282
}

dev-support/jenkins.sh

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ function run_ci() {
115115
TESTPATCHBIN="${WORKSPACE}/${YETUS}/precommit/src/main/shell/test-patch.sh"
116116

117117
# this must be clean for every run
118-
if [[ -d "${WORKSPACE}/${PATCHDIR}" ]]; then
119-
rm -rf "${WORKSPACE:?}/${PATCHDIR}"
118+
if [[ -d "${PATCHDIR}" ]]; then
119+
rm -rf "${PATCHDIR:?}"
120120
fi
121-
mkdir -p "${WORKSPACE}/${PATCHDIR}"
121+
mkdir -p "${PATCHDIR}"
122122

123123
# if given a JIRA issue, process it. If CHANGE_URL is set
124124
# (e.g., Github Branch Source plugin), process it.
@@ -128,23 +128,23 @@ function run_ci() {
128128
if [[ -n "${JIRA_ISSUE_KEY}" ]]; then
129129
YETUS_ARGS+=("${JIRA_ISSUE_KEY}")
130130
elif [[ -z "${CHANGE_URL}" ]]; then
131-
echo "Full build skipped" >"${WORKSPACE}/${PATCHDIR}/report.html"
131+
echo "Full build skipped" >"${PATCHDIR}/report.html"
132132
exit 0
133133
fi
134134

135-
YETUS_ARGS+=("--patch-dir=${WORKSPACE}/${PATCHDIR}")
135+
YETUS_ARGS+=("--patch-dir=${PATCHDIR}")
136136

137137
# where the source is located
138-
YETUS_ARGS+=("--basedir=${WORKSPACE}/${SOURCEDIR}")
138+
YETUS_ARGS+=("--basedir=${SOURCEDIR}")
139139

140140
# our project defaults come from a personality file
141141
YETUS_ARGS+=("--project=hadoop")
142-
YETUS_ARGS+=("--personality=${WORKSPACE}/${SOURCEDIR}/dev-support/bin/hadoop.sh")
142+
YETUS_ARGS+=("--personality=${SOURCEDIR}/dev-support/bin/hadoop.sh")
143143

144144
# lots of different output formats
145-
YETUS_ARGS+=("--brief-report-file=${WORKSPACE}/${PATCHDIR}/brief.txt")
146-
YETUS_ARGS+=("--console-report-file=${WORKSPACE}/${PATCHDIR}/console.txt")
147-
YETUS_ARGS+=("--html-report-file=${WORKSPACE}/${PATCHDIR}/report.html")
145+
YETUS_ARGS+=("--brief-report-file=${PATCHDIR}/brief.txt")
146+
YETUS_ARGS+=("--console-report-file=${PATCHDIR}/console.txt")
147+
YETUS_ARGS+=("--html-report-file=${PATCHDIR}/report.html")
148148

149149
# enable writing back to Github
150150
YETUS_ARGS+=("--github-token=${GITHUB_TOKEN}")
@@ -206,7 +206,49 @@ function run_ci() {
206206
"${TESTPATCHBIN}" "${YETUS_ARGS[@]}"
207207
}
208208

209-
# Check if the CI needs to be run, if so, do so :)
210-
if check_ci_run; then
211-
run_ci
209+
## @description Cleans up the processes started by YETUS
210+
function cleanup_ci_proc() {
211+
# See YETUS-764
212+
if [ -f "${PATCHDIR}/pidfile.txt" ]; then
213+
echo "test-patch process appears to still be running: killing"
214+
kill "$(cat "${PATCHDIR}/pidfile.txt")" || true
215+
sleep 10
216+
fi
217+
if [ -f "${PATCHDIR}/cidfile.txt" ]; then
218+
echo "test-patch container appears to still be running: killing"
219+
docker kill "$(cat "${PATCHDIR}/cidfile.txt")" || true
220+
fi
221+
}
222+
223+
## @description Invokes github_status_recovery in YETUS's precommit
224+
function github_status_recovery() {
225+
YETUS_ARGS+=("--github-token=${GITHUB_TOKEN}")
226+
YETUS_ARGS+=("--patch-dir=${PATCHDIR}")
227+
TESTPATCHBIN="${WORKSPACE}/${YETUS}/precommit/src/main/shell/github-status-recovery.sh"
228+
/usr/bin/env bash "${TESTPATCHBIN}" "${YETUS_ARGS[@]}" "${EXTRA_ARGS}" || true
229+
}
230+
231+
if [ -z "$1" ]; then
232+
echo "Must specify an argument for jenkins.sh"
233+
echo "run_ci - Runs the CI based on platform image as defined by DOCKERFILE"
234+
echo "cleanup_ci_proc - Cleans up the processes spawned for running the CI"
235+
echo "github_status_recovery - Sends Github status (refer to YETUS precommit for more details)"
236+
exit 1
237+
fi
238+
239+
# Process arguments to jenkins.sh
240+
if [ "$1" == "run_ci" ]; then
241+
# Check if the CI needs to be run, if so, do so :)
242+
if check_ci_run; then
243+
run_ci
244+
else
245+
echo "No C++ file/C++ build/platform changes found, will not run CI"
246+
fi
247+
elif [ "$1" == "cleanup_ci_proc" ]; then
248+
cleanup_ci_proc
249+
elif [ "$1" == "github_status_recovery" ]; then
250+
github_status_recovery
251+
else
252+
echo "Don't know how to process $1"
253+
exit 1
212254
fi

0 commit comments

Comments
 (0)