diff options
author | Christophe Lyon <christophe.lyon@linaro.org> | 2019-03-20 22:35:50 +0000 |
---|---|---|
committer | Christophe Lyon <christophe.lyon@linaro.org> | 2019-03-21 11:28:05 +0000 |
commit | 759bf5b1e72cf947786a158b1da2e363f61ceef0 (patch) | |
tree | da7cec516075696ed6444986b8ce5c69edc4032d /jenkins-helpers.sh | |
parent | ff044c8ba5afd5a734316bea4afe872dc44ebde3 (diff) |
start-container-docker.sh, jenkins-helpers.sh: Add --ssh_info option
The new boolean --ssh_info option of start-container-docker.sh enables
passing ssh_host and ssh_port variables to the command executed in the
container via the environment.
The remote_exec helper is enhanced to support passing environment
variables.
Change-Id: Ic068220d52541ada2ea6b4a26f40730788babf9d
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 26533cdd..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[@]}" ) } |