8d3e85d73e3754e0b9b649e8d715fd352e9e4a23
[releng/builder.git] / jjb / integration / copy-common-functions.sh
1 #!/bin/bash
2
3 # Copy the whole script to /tmp/common-functions.sh and to remote nodes but
4 # only if this script itself is executing and not sourced. jenkins prepends this
5 # script to the common-functions.sh script when adding it to the robot minion.
6 # jenkins will then execute the script. The if check below checks that the
7 # script is executing rather than being sourced. When executed the condition
8 # is true and copies the script. In the false path this copy below is skipped
9 # and the sourcing continues so that the appended common-function.sh ends up sourced.
10 if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
11     echo "Copying common-functions.sh to /tmp"
12     cp "${0}" /tmp/common-functions.sh
13
14     source /tmp/v/openstack/bin/activate
15     # shellcheck disable=SC2207
16     ips=($(openstack stack show -f json -c outputs "$STACK_NAME" | \
17                jq -r '.outputs[] | select(.output_key | match("^vm_[0-9]+_ips$")) | .output_value | .[]'))
18     for ip in "${ips[@]}"; do
19         echo "Copying common-functions.sh to ${ip}:/tmp"
20         scp /tmp/common-functions.sh ${ip}:/tmp
21     done
22     exit 0
23 fi