Skip to content

Commit

Permalink
ci: Rewrite jobscript creation
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
ChristianTackeGSI committed May 30, 2023
1 parent 2598b60 commit fa7108b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
16 changes: 5 additions & 11 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,11 @@ def jobMatrix(String prefix, String type, List specs) {
sh "cat ${jobscript}"
sh "bash ${jobscript}"
} else {
def containercmd = "singularity exec -B/shared ${env.SINGULARITY_CONTAINER_ROOT}/fairroot/${os}.${ver}.sif bash -l -c \\\"${ctestcmd}\\\""
sh """\
echo \"echo \\\"*** Job started at .......: \\\$(date -R)\\\"\" >> ${jobscript}
echo \"echo \\\"*** Job ID ...............: \\\${SLURM_JOB_ID}\\\"\" >> ${jobscript}
echo \"echo \\\"*** Compute node .........: \\\$(hostname -f)\\\"\" >> ${jobscript}
echo \"unset http_proxy\" >> ${jobscript}
echo \"unset HTTP_PROXY\" >> ${jobscript}
echo \"${containercmd}\" >> ${jobscript}
"""
sh "cat ${jobscript}"
sh "./slurm-submit.sh \"FairRoot \${JOB_BASE_NAME} ${label}\" ${jobscript}"
def container = "${os}.${ver}.sif"
sh(label: "Create Slurm Job Script", script: """
exec test/ci/slurm-create-jobscript.sh "${label}" "${container}" "${jobscript}" ${ctestcmd}
""")
sh "./test/ci/slurm-submit.sh \"FairRoot \${JOB_BASE_NAME} ${label}\" ${jobscript}"
}
if (check == "warnings" || check == "doxygen") {
discoverGitReferenceBuild()
Expand Down
41 changes: 41 additions & 0 deletions test/ci/slurm-create-jobscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /bin/bash

if [ $# -lt 4 ]
then
echo "*** Please call like: $0 LABEL CONTAINER JOBSH CTEST [CTESTARG ...]"
exit 1
fi

label="$1"; shift
container="$1"; shift
jobsh="$1"; shift
# Convert commandline array into single string, with proper quoting
ctestcmd="$(printf ' %q' "$@")"
# Strip leading space
ctestcmd="${ctestcmd:1}"

echo "*** Creating job script ..: ${jobsh}"

(
echo '# #! /bin/bash'
echo "# export LABEL=${label}"
echo ' echo "*** Job started at .......: $(date -R)"'
echo ' echo "*** Job ID ...............: $SLURM_JOB_ID"'
echo ' echo "*** Compute node .........: $(hostname -f)"'
echo "# source <(sed -e '/^#/d' -e '/^export/!s/^.*=/export &/' /etc/environment)"
printf '# ./test/test-start-container.sh %q %q\n' "${container}" "${ctestcmd}"
echo '# retval=$?'
echo '# mkdir -p build'
echo '# echo $retval >"build/${LABEL}-last-exit-code"'
echo '# exit $retval'
echo 'newhomedir="$(mktemp --tmpdir -d FairRoot-CI-home.XXXXXX)"'
echo ' echo "*** Temporary homedir ....: $newhomedir"'
echo ' unset http_proxy'
echo ' unset HTTP_PROXY'
printf 'singularity exec -B/shared -H "${newhomedir}" %q bash -l -c %q\n' \
"${SINGULARITY_CONTAINER_ROOT}/fairroot/${container}" \
"${ctestcmd}"
) >> "$jobsh"

echo "*** Content:"
sed -e 's/^/ /' "$jobsh"
File renamed without changes.

0 comments on commit fa7108b

Please sign in to comment.