Skip to content

Commit 055fabb

Browse files
Put informative labels on shell steps
Many sh or bat pipeline steps have an uninformative label. Groovy uses the script as a label by default, but this is uninformative when the script is something like "./steps.sh", and it's unreadable or truncated when the script is very long. In such cases, use an informative label, containing the job name. In particular, this makes it possible to quickly search for the execution of a given all.sh component in the Jenkins pipeline view: search for "steps.sh #${job_name}", e.g. "steps.sh #all_u16-test_clang_opt". Signed-off-by: Gilles Peskine <[email protected]>
1 parent 68ddf82 commit 055fabb

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

vars/common.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def get_branch_information() {
162162
script: docker_script(
163163
platform, "./tests/scripts/all.sh", "--list-components"
164164
),
165+
label: "./tests/scripts/all.sh --list-components #$platform",
165166
returnStdout: true
166167
).trim().split('\n')
167168
if (all_all_sh_components == []) {
@@ -170,6 +171,7 @@ def get_branch_information() {
170171
platform, "./tests/scripts/all.sh",
171172
"--list-all-components"
172173
),
174+
label: "./tests/scripts/all.sh --list-all-components",
173175
returnStdout: true
174176
).trim().split('\n')
175177
}
@@ -235,7 +237,7 @@ def maybe_notify_github(context, state, description) {
235237
}
236238

237239
def archive_zipped_log_files(job_name) {
238-
sh """\
240+
sh label: "rename+compress *.log", script: """\
239241
for i in *.log; do
240242
[ -f "\$i" ] || break
241243
mv "\$i" "$job_name-\$i"

vars/gen_jobs.groovy

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def gen_simple_windows_jobs(label, script) {
3636
checkout_repo.checkout_repo()
3737
timeout(time: common.perJobTimeout.time,
3838
unit: common.perJobTimeout.unit) {
39-
bat script
39+
bat script: script, label: label
4040
}
4141
}
4242
} catch (err) {
@@ -154,12 +154,13 @@ ${extra_setup_code}
154154
unit: common.perJobTimeout.unit) {
155155
try {
156156
if (use_docker) {
157-
sh common.docker_script(
157+
sh script: common.docker_script(
158158
platform, "/var/lib/build/steps.sh"
159-
)
159+
), label: "docker run steps.sh #${job_name}"
160160
} else {
161161
dir('src') {
162-
sh './steps.sh'
162+
sh script: './steps.sh',
163+
label: "docker run steps.sh #${job_name}"
163164
}
164165
}
165166
} finally {
@@ -265,7 +266,8 @@ def gen_abi_api_checking_job(platform) {
265266
/* The credentials here are the SSH credentials for accessing the repositories.
266267
They are defined at {JENKINS_URL}/credentials */
267268
withCredentials([sshUserPrivateKey(credentialsId: credentials_id, keyFileVariable: 'keyfile')]) {
268-
sh "GIT_SSH_COMMAND=\"ssh -i ${keyfile}\" git fetch origin ${CHANGE_TARGET}"
269+
sh script: "GIT_SSH_COMMAND=\"ssh -i ${keyfile}\" git fetch origin ${CHANGE_TARGET}",
270+
label: "git fetch origin ${CHANGE_TARGET}"
269271
}
270272
writeFile file: 'steps.sh', text: """\
271273
#!/bin/sh
@@ -283,9 +285,9 @@ scripts/abi_check.py -o FETCH_HEAD -n HEAD -s identifiers --brief
283285
}
284286
timeout(time: common.perJobTimeout.time,
285287
unit: common.perJobTimeout.unit) {
286-
sh common.docker_script(
288+
sh script: common.docker_script(
287289
platform, "/var/lib/build/steps.sh"
288-
)
290+
), label: "steps.sh #${job_name}"
289291
}
290292
} catch (err) {
291293
failed_builds[job_name] = true
@@ -334,9 +336,9 @@ fi
334336
timeout(time: common.perJobTimeout.time,
335337
unit: common.perJobTimeout.unit) {
336338
try {
337-
sh common.docker_script(
339+
sh script: common.docker_script(
338340
platform, "/var/lib/build/steps.sh"
339-
)
341+
), label: "steps.sh #${job_name}"
340342
dir('src') {
341343
String coverage_log = readFile('coverage-summary.txt')
342344
coverage_details['coverage'] = coverage_log.substring(
@@ -392,7 +394,7 @@ def gen_mbed_os_example_job(repo, branch, example, compiler, platform, raas) {
392394
try {
393395
deleteDir()
394396
/* Create python virtual environment and install mbed tools */
395-
sh """\
397+
sh label: "virtualenv #${job_name}", script: """\
396398
ulimit -f 20971520
397399
virtualenv $WORKSPACE/mbed-venv
398400
. $WORKSPACE/mbed-venv/bin/activate
@@ -406,7 +408,7 @@ pip install mbed-host-tests
406408
/* If the job is targeting an example repo, then we wish to use the versions
407409
* of Mbed OS, TLS and Crypto specified by the mbed-os.lib file. */
408410
if (env.TARGET_REPO == 'example') {
409-
sh """\
411+
sh label: "mbed deploy #${job_name}", script: """\
410412
ulimit -f 20971520
411413
. $WORKSPACE/mbed-venv/bin/activate
412414
mbed config root .
@@ -418,7 +420,7 @@ mbed deploy -vv
418420
* checking it out twice. Mbed deploy is still run in case other libraries
419421
* are required to be deployed. We then check out Mbed OS, TLS and Crypto
420422
* according to the job parameters. */
421-
sh """\
423+
sh label: "rm mbed-os.lib; mbed deploy #${job_name}", script: """\
422424
ulimit -f 20971520
423425
. $WORKSPACE/mbed-venv/bin/activate
424426
rm -f mbed-os.lib
@@ -429,7 +431,7 @@ mbed deploy -vv
429431
deleteDir()
430432
checkout_repo.checkout_mbed_os()
431433
/* Check that python requirements are up to date */
432-
sh """\
434+
sh label: "pip install #${job_name}", script: """\
433435
ulimit -f 20971520
434436
. $WORKSPACE/mbed-venv/bin/activate
435437
pip install -r requirements.txt
@@ -443,14 +445,14 @@ pip install -r requirements.txt
443445
if (example == 'atecc608a') {
444446
tag_filter = "--tag-filters HAS_CRYPTOKIT"
445447
}
446-
sh """\
448+
sh label: "mbed compile #${job_name}", script: """\
447449
ulimit -f 20971520
448450
. $WORKSPACE/mbed-venv/bin/activate
449451
mbed compile -m ${platform} -t ${compiler}
450452
"""
451453
for (int attempt = 1; attempt <= 3; attempt++) {
452454
try {
453-
sh """\
455+
sh label: "mbedhtrun #${job_name}#${attempt}", script: """\
454456
ulimit -f 20971520
455457
if [ -e BUILD/${platform}/${compiler}/${example}.bin ]
456458
then
@@ -573,7 +575,9 @@ def gen_dockerfile_builder_job(platform, overwrite=false) {
573575
node('dockerfile-builder') {
574576
def image_exists = false
575577
if (!overwrite) {
576-
image_exists = sh(script: check_docker_image, returnStatus: true) == 0
578+
image_exists = sh(script: check_docker_image,
579+
label: "check_docker_image ${tag}",
580+
returnStatus: true) == 0
577581
}
578582
if (overwrite || !image_exists) {
579583
dir('docker') {
@@ -585,7 +589,7 @@ def gen_dockerfile_builder_job(platform, overwrite=false) {
585589
extra_build_args = '--build-arg [email protected]'
586590

587591
withCredentials([string(credentialsId: 'DOCKER_AUTH', variable: 'TOKEN')]) {
588-
sh """\
592+
sh label: ">.docker/config.json #${platform}", script: """\
589593
mkdir -p ${env.HOME}/.docker
590594
cat > ${env.HOME}/.docker/config.json << EOF
591595
{
@@ -600,12 +604,12 @@ chmod 0600 ${env.HOME}/.docker/config.json
600604
"""
601605
}
602606
} else {
603-
sh """\
607+
sh label: "docker login #${platform}", script: """\
604608
aws ecr get-login-password | docker login --username AWS --password-stdin $common.docker_ecr
605609
"""
606610
}
607611

608-
sh """\
612+
sh label: "docker push #${tag}", script: """\
609613
# Use BuildKit and a remote build cache to pull only the reuseable layers
610614
# from the last successful build for this platform
611615
DOCKER_BUILDKIT=1 docker build \

0 commit comments

Comments
 (0)