diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2019-02-28 07:38:17 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2019-03-06 12:41:20 +0000 |
commit | acd4dfe5cbee22fee97c40afb0a3a2df6722e96a (patch) | |
tree | fad7f601260b55b17be68869c0bdf44101af9e08 /jenkins-helpers.sh | |
parent | 849ca36d4278b0799f7a3baf5285a741aff95463 (diff) |
start-container-docker.sh, docker-run.sh: Rework --ssh_info support
Instead of a hack in docker-run.sh add ability to pass environment
variables in remote_exec(). Use this to pass ssh_host/ssh_port via
container_exec() function.
Change-Id: Ic8f7bb3c3ae94b501eb475e90b892c0d769dd0dd
Diffstat (limited to 'jenkins-helpers.sh')
-rw-r--r-- | jenkins-helpers.sh | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh index 5573f391..8f406820 100644 --- a/jenkins-helpers.sh +++ b/jenkins-helpers.sh @@ -224,18 +224,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=() @@ -244,7 +248,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[@]}" ) } |