Skip to content

Commit 3fd5c94

Browse files
authored
Add -e and -o pipefail to exit on failures more consistently. (elastic#135)
* Add -e and -o pipefail to exit on failures more consistently.
1 parent d253ef1 commit 3fd5c94

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

night_rally/fixtures/ansible/Vagrantfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def rally_sudoers
3939
# Use single quotes to avoid interpolating EOF2 intended for bash
4040
# tilde before 'EOF' allows indenting heredoc without passing the extra leading spaces to actual bash command
4141
<<~'EOF'
42+
set -eo pipefail
4243
cat >/etc/sudoers.d/rally_user <<EOF2
4344
Defaults:rally !requiretty
4445
rally ALL = (ALL) NOPASSWD: ALL
@@ -48,7 +49,7 @@ end
4849

4950
def install_jenkins_user
5051
<<~EOF
51-
set +x
52+
set -eo pipefail
5253
groupadd -g 1010 jenkins
5354
useradd -u 1010 -g 1010 -s /bin/bash -m -k /etc/skel -d /var/lib/jenkins jenkins
5455
mkdir /var/lib/jenkins/.ssh
@@ -62,6 +63,7 @@ end
6263

6364
def install_rally_user
6465
<<~EOF
66+
set -eo pipefail
6567
groupadd -g 1011 rally
6668
useradd -u 1011 -g 1011 -s /bin/bash -m -k /etc/skel -d /home/rally rally
6769
mkdir /home/rally/.ssh
@@ -75,6 +77,7 @@ end
7577

7678
def install_vault
7779
<<~EOF
80+
set -eo pipefail
7881
CUR_HOME=$HOME
7982
curl -fsS -o ${CUR_HOME}/vault.zip https://releases.hashicorp.com/vault/1.1.1/vault_1.1.1_linux_amd64.zip
8083
sudo unzip ${CUR_HOME}/vault.zip -d /usr/local/bin
@@ -85,6 +88,7 @@ end
8588

8689
def install_rally_source(rally_repo, rally_branch, rally_sha)
8790
<<~EOF
91+
set -eo pipefail
8892
apt-get update
8993
apt-get install -y python-virtualenv
9094
apt-get install -y python3-pip
@@ -128,7 +132,7 @@ def install_night_rally_test_script(base_ip, target_node_ip_addresses)
128132
129133
cat >/var/lib/jenkins/test_nightly.sh <<"EOF2"
130134
#!/usr/bin/env bash
131-
set -e
135+
set -eo pipefail
132136
source /var/lib/jenkins/env_test_script
133137
# release-license is oss just because it's the default option in the JJB dropdown; will be ignored in nightly mode
134138
night_rally --target-host="${TARGET_HOSTS}" --race-configs="resources/race-configs-group-1.json" --effective-start-date="" --mode="nightly" --version="master" --release-license="oss" --release-x-pack-components=""
@@ -137,15 +141,15 @@ def install_night_rally_test_script(base_ip, target_node_ip_addresses)
137141
138142
cat >/var/lib/jenkins/test_release.sh <<"EOF2"
139143
#!/usr/bin/env bash
140-
set -e
144+
set -eo pipefail
141145
source /var/lib/jenkins/env_test_script
142146
night_rally --target-host="${TARGET_HOSTS}" --race-configs="resources/race-configs-group-1.json" --effective-start-date="" --mode="release" --version="6.7.0" --release-license="oss" --release-x-pack-components=""
143147
night_rally --target-host="${TARGET_HOSTS}" --race-configs="resources/race-configs-group-2.json" --effective-start-date="" --mode="release" --version="6.7.0" --release-license="oss" --release-x-pack-components=""
144148
EOF2
145149
146150
cat >/var/lib/jenkins/test_longrunning.sh <<"EOF2"
147151
#!/usr/bin/env bash
148-
set -e
152+
set -eo pipefail
149153
source /var/lib/jenkins/env_test_script
150154
/var/lib/jenkins/night_rally/external/scripts/long-running-benchmarks.sh
151155
EOF2
@@ -157,6 +161,7 @@ end
157161

158162
def install_java(major_ver)
159163
<<~EOF
164+
set -eo pipefail
160165
jdk_url=$(curl -fsSL https://jvm-catalog.elastic.co/jdk/latest_openjdk_#{major_ver}_linux | jq -r .url)
161166
cd /var/lib/jenkins
162167
mkdir -p .java/openjdk#{major_ver}
@@ -171,6 +176,7 @@ end
171176

172177
def symlink_java_8
173178
<<~EOF
179+
set -eo pipefail
174180
ln -s /usr/lib/jvm/java-8-openjdk-amd64 /var/lib/jenkins/.java/java8
175181
# dangling symlinks cause issues to certain gradle versions
176182
rm -f /usr/lib/jvm/java-8-openjdk-amd64/src.zip
@@ -179,7 +185,7 @@ end
179185

180186
def pass_additional_jenkins_env_vars
181187
<<~EOF
182-
set +x
188+
set +x -eo pipefail
183189
cat >>/var/lib/jenkins/.profile <<EOF2
184190
export VAULT_ADDR=https://secrets.elastic.co:8200
185191
export RALLY_METRICS_STORE_CREDENTIAL_PATH=${RALLY_METRICS_STORE_CREDENTIAL_PATH:-/secret/rally/cloud/vagrant-test-rally-metrics}

0 commit comments

Comments
 (0)