diff options
Diffstat (limited to 'jenkins-helpers.sh')
-rw-r--r-- | jenkins-helpers.sh | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh index 5291873e..65428d9a 100644 --- a/jenkins-helpers.sh +++ b/jenkins-helpers.sh @@ -246,18 +246,22 @@ print_tester_label_for_target () } # Run command on remote machine in given directory via ssh on a given port -# "$1" -- <host>[:<port>[:<dir>[:<ssh_opts>]]] +# "$1" -- <host>[:<port>[:<dir>[:<ssh_opts>[:<env>]]]] # "$2, $3, etc" -- command and its arguments # E.g., remote_exec dev-01.tcwglab::/tmp find -name "my file.bak" +# NOTE: The environment variables are not escaped, so pass only simple things. +# This is because we want ability to pass multiple variables "a=b c=d", +# and escaping will make that into a single a="b c=d" variable. remote_exec () { ( set -euf -o pipefail - local host="$(echo $1 | cut -d: -f 1)" - local port="$(echo $1 | cut -s -d: -f 2)" - local dir="$(echo $1 | cut -s -d: -f 3)" - local opts="$(echo $1 | cut -s -d: -f 4)" + local host="$(echo "$1" | cut -d: -f 1)" + local port="$(echo "$1" | cut -s -d: -f 2)" + local dir="$(echo "$1" | cut -s -d: -f 3)" + local opts="$(echo "$1" | cut -s -d: -f 4)" + local env_vars="$(echo "$1" | cut -s -d: -f 5)" shift local -a cmd cmd=() @@ -266,7 +270,7 @@ remote_exec () # Be careful to prepend statements before ${cmd[@]} only if necessary. # E.g., when triggering jobs via jenkins-cli, the command is not a binary, # so we can't "exec" it. - ssh $opts ${port:+-p$port} $host "${dir:+cd "$(printf '%q' "$dir")" && exec }${cmd[@]}" + ssh $opts ${port:+-p$port} $host "${env_vars:+export $env_vars && }${dir:+cd "$(printf '%q' "$dir")" && exec }${cmd[@]}" ) } @@ -1122,11 +1126,6 @@ run_step () run_step_active=true fi - run_step_artifacts=$run_step_top_artifacts/$run_step_count-$pretty_step - - rm -rf "$run_step_artifacts" - mkdir -p "$run_step_artifacts" - if $run_step_active; then local skip=false case "$run_step_status:$run_mode" in @@ -1147,6 +1146,11 @@ run_step () esac if ! $skip; then + run_step_artifacts=$run_step_top_artifacts/$(printf "%02d" $run_step_count)-$pretty_step + + rm -rf "$run_step_artifacts" + mkdir -p "$run_step_artifacts" + echo "RUNNING ${step[@]}; see tail -f $run_step_artifacts/console.log" run_step_status=0 eval "if $run_step_verbose; then set -x; else set +x; fi; ${step[@]}" 2>&1 | tee -a $run_step_top_artifacts/console.log > $run_step_artifacts/console.log & |