summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2022-09-16 15:30:25 +0000
committerLaurent Alfonsi <laurent.alfonsi@linaro.org>2022-09-22 21:27:01 +0000
commitc96e6e9e54f3fd1c0f59f45429e914a06b005071 (patch)
tree483e97acf262824636ad0cabe33ce6b78f917965
parent0fbbe2bf133bf76663717da32a21fa605b4d37d0 (diff)
jenkins-helpers.sh (run_step): Support changing environment
... for subsequent steps. This works by generating a source-able file patch_env.sh in the artifacts of the current step. Run_step() then sources this file to update the environment. Note that we build walls around individual steps on purpose. This allows us to SKIP several initial steps during bisect builds, and have a clear record of environment modifications in artifacts/NN-step/patch-env.sh scripts, which could be applied in correct order. At the moment this all is done just to change rr[update_baseline] from "onsuccess" to "init" for new loops ... which feels like an overkill. Change-Id: Ib92d6cfa76e9f59c91e8052f192e3e5e3de9a10e
-rw-r--r--jenkins-helpers.sh46
-rw-r--r--round-robin.sh8
2 files changed, 46 insertions, 8 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh
index 08bd94e1..df888a9c 100644
--- a/jenkins-helpers.sh
+++ b/jenkins-helpers.sh
@@ -1304,6 +1304,26 @@ finishing at step \"$run_step_finish_at\""
rm -f $run_step_top_artifacts/results
}
+# Patch environment for subsequent steps. This works by generating
+# a source-able file patch-env.sh in the artifacts of the current step.
+# Run_step() then sources this file to update the environment.
+# Note that we build walls around individual steps on purpose. This allows
+# us to SKIP several initial steps during bisect builds, and have a clear
+# record of environment modifications in artifacts/NN-step/patch-env.sh
+# scripts, which could be applied in correct order.
+#
+# $@: parameters in the format that convert_args_to_variables() understands.
+run_step_patch_env ()
+{
+ # !!! Each step is limited to a single invocation of run_step_patch_env()
+ # !!! due to manifest_push() re-writing the manifest.
+ assert_with_msg "patch-env.sh manifest already exists" \
+ ! [ -e $run_step_artifacts/patch-env.sh ]
+ manifest_push $run_step_artifacts/patch-env.sh
+ convert_args_to_variables "$@"
+ manifest_pop
+}
+
# Run execution step and handle its failure as requested
# This function manages
# 1. step skipping -- skip steps before START_AT and after FINISH_AT,
@@ -1355,6 +1375,11 @@ run_step ()
run_step_count=$(($run_step_count+1))
+ local full_step_name
+ full_step_name=$(printf "%02d" $run_step_count)-$pretty_step
+ # This is used when accessing the workspace
+ run_step_artifacts=$run_step_top_artifacts/$full_step_name
+
# Start running steps if:
# the current step is the starting step OR
# we haven't run any steps yet and
@@ -1395,10 +1420,6 @@ run_step ()
EOF
fi
- local full_step_name
- full_step_name=$(printf "%02d" $run_step_count)-$pretty_step
- # This is used when accessing the workspace
- run_step_artifacts=$run_step_top_artifacts/$full_step_name
local log_url=""
if [ -v BUILD_URL ]; then
# Link to jenkins, valid once the job has finished
@@ -1410,7 +1431,17 @@ EOF
echo "RUNNING ${step[*]}; see tail -f $run_step_artifacts/console.log" $log_url
run_step_status=0
- eval "if $run_step_verbose; then set -x; else set +x; fi; ${step[*]}" 2>&1 | ts -s "%T" > $run_step_artifacts/console.log &
+ # We are running below "eval" in a sub-shell (due to "&"), so
+ # any modifications to environment by "${step[*]}" will be lost.
+ # The steps can modify environment for subsequent steps by using
+ # run_step_patch_env().
+ eval "
+if $run_step_verbose; then
+ set -x
+else
+ set +x
+fi
+${step[*]}" 2>&1 | ts -s "%T" > $run_step_artifacts/console.log &
wait $! || run_step_status=$?
xz $run_step_artifacts/console.log
@@ -1448,6 +1479,11 @@ $success_result
EOF
fi
+ if [ -f $run_step_artifacts/patch-env.sh ]; then
+ # shellcheck disable=SC1090
+ source $run_step_artifacts/patch-env.sh
+ fi
+
if [ x"$pretty_step" = x"$run_step_finish_at" ]; then
run_step_active=false
fi
diff --git a/round-robin.sh b/round-robin.sh
index 901ac0ab..f25af57b 100644
--- a/round-robin.sh
+++ b/round-robin.sh
@@ -124,9 +124,9 @@ breakup_changed_components ()
# is.
reset_artifacts ()
{
- # Note: not running in a sub-shell to export setting of
- # rr[update_baseline] to "init" for missing baselines.
-
+ (
+ set -euf -o pipefail
+
# Clean ${rr[top_artifacts]} but preserve
# - ${rr[top_artifacts]}/console.log and $run_step_artifacts/console.log, which
# are being written to by run_step().
@@ -142,6 +142,7 @@ reset_artifacts ()
&& [ x"$(git ls-remote --heads https://git-us.linaro.org/toolchain/ci/base-artifacts.git refs/heads/${rr[baseline_branch]})" = x"" ]; then
echo "WARNING: BASELINE IS NOT FOUND; INITIALIZING BASELINE"
rr[update_baseline]="init"
+ run_step_patch_env "==rr[update_baseline]" "init"
fi
# Clone base-artifacts here so that bisect runs (which skip this step)
@@ -210,6 +211,7 @@ EOF
# Note that we need to copy the whole directory to correctly handle
# builds that fail before all their components are checked out.
rsync -a base-artifacts/git/ ${rr[top_artifacts]}/git/
+ )
}
get_baseline_git ()