Skip to content

Commit fa7108b

Browse files
ci: Rewrite jobscript creation
Refactor job script creation into its own shell script. This should improve general readability. Also use the opportunity and create a dedicated, temporary home directory for the CI run. This way all files created in the home directory by the job do not end up in the real one. (cherry picked from commit e4ecb3c)
1 parent 2598b60 commit fa7108b

3 files changed

Lines changed: 46 additions & 11 deletions

File tree

Jenkinsfile

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,11 @@ def jobMatrix(String prefix, String type, List specs) {
5050
sh "cat ${jobscript}"
5151
sh "bash ${jobscript}"
5252
} else {
53-
def containercmd = "singularity exec -B/shared ${env.SINGULARITY_CONTAINER_ROOT}/fairroot/${os}.${ver}.sif bash -l -c \\\"${ctestcmd}\\\""
54-
sh """\
55-
echo \"echo \\\"*** Job started at .......: \\\$(date -R)\\\"\" >> ${jobscript}
56-
echo \"echo \\\"*** Job ID ...............: \\\${SLURM_JOB_ID}\\\"\" >> ${jobscript}
57-
echo \"echo \\\"*** Compute node .........: \\\$(hostname -f)\\\"\" >> ${jobscript}
58-
echo \"unset http_proxy\" >> ${jobscript}
59-
echo \"unset HTTP_PROXY\" >> ${jobscript}
60-
echo \"${containercmd}\" >> ${jobscript}
61-
"""
62-
sh "cat ${jobscript}"
63-
sh "./slurm-submit.sh \"FairRoot \${JOB_BASE_NAME} ${label}\" ${jobscript}"
53+
def container = "${os}.${ver}.sif"
54+
sh(label: "Create Slurm Job Script", script: """
55+
exec test/ci/slurm-create-jobscript.sh "${label}" "${container}" "${jobscript}" ${ctestcmd}
56+
""")
57+
sh "./test/ci/slurm-submit.sh \"FairRoot \${JOB_BASE_NAME} ${label}\" ${jobscript}"
6458
}
6559
if (check == "warnings" || check == "doxygen") {
6660
discoverGitReferenceBuild()

test/ci/slurm-create-jobscript.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! /bin/bash
2+
3+
if [ $# -lt 4 ]
4+
then
5+
echo "*** Please call like: $0 LABEL CONTAINER JOBSH CTEST [CTESTARG ...]"
6+
exit 1
7+
fi
8+
9+
label="$1"; shift
10+
container="$1"; shift
11+
jobsh="$1"; shift
12+
# Convert commandline array into single string, with proper quoting
13+
ctestcmd="$(printf ' %q' "$@")"
14+
# Strip leading space
15+
ctestcmd="${ctestcmd:1}"
16+
17+
echo "*** Creating job script ..: ${jobsh}"
18+
19+
(
20+
echo '# #! /bin/bash'
21+
echo "# export LABEL=${label}"
22+
echo ' echo "*** Job started at .......: $(date -R)"'
23+
echo ' echo "*** Job ID ...............: $SLURM_JOB_ID"'
24+
echo ' echo "*** Compute node .........: $(hostname -f)"'
25+
echo "# source <(sed -e '/^#/d' -e '/^export/!s/^.*=/export &/' /etc/environment)"
26+
printf '# ./test/test-start-container.sh %q %q\n' "${container}" "${ctestcmd}"
27+
echo '# retval=$?'
28+
echo '# mkdir -p build'
29+
echo '# echo $retval >"build/${LABEL}-last-exit-code"'
30+
echo '# exit $retval'
31+
echo 'newhomedir="$(mktemp --tmpdir -d FairRoot-CI-home.XXXXXX)"'
32+
echo ' echo "*** Temporary homedir ....: $newhomedir"'
33+
echo ' unset http_proxy'
34+
echo ' unset HTTP_PROXY'
35+
printf 'singularity exec -B/shared -H "${newhomedir}" %q bash -l -c %q\n' \
36+
"${SINGULARITY_CONTAINER_ROOT}/fairroot/${container}" \
37+
"${ctestcmd}"
38+
) >> "$jobsh"
39+
40+
echo "*** Content:"
41+
sed -e 's/^/ /' "$jobsh"
File renamed without changes.

0 commit comments

Comments
 (0)