Skip to content

Commit 0f7e164

Browse files
authored
Merge pull request #101 from buildkite-plugins/toote_compressed_ignore
Enhance ignore missing with compressed
2 parents 7ef7d10 + 6a4d64e commit 0f7e164

2 files changed

Lines changed: 37 additions & 33 deletions

File tree

hooks/pre-command

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,17 @@ bk_agent() {
6464
options+=("${@}") # all the rest
6565

6666
echo "~~~ Downloading artifacts ${EXTRA_MESSAGE}"
67-
if ! buildkite-agent artifact "${options[@]}"; then
68-
if [[ "${BUILDKITE_PLUGIN_ARTIFACTS_IGNORE_MISSING:-"false"}" != "false" ]]; then
69-
echo "Ignoring error in download of" "${@: -2}"
70-
else
71-
echo "Error in download of" "${@: -2}"
72-
return 1
73-
fi
74-
fi
67+
buildkite-agent artifact "${options[@]}"
68+
}
7569

76-
return 0
70+
handle_bk_error() {
71+
local filename="$1"
72+
if [[ "${BUILDKITE_PLUGIN_ARTIFACTS_IGNORE_MISSING:-"false"}" != "false" ]]; then
73+
echo "Ignoring error in download of ${filename}"
74+
else
75+
echo "Error in download of ${filename}"
76+
exit 1
77+
fi
7778
}
7879

7980
handle_relocation() {
@@ -114,34 +115,38 @@ fi
114115
workdir="${BUILDKITE_PLUGIN_ARTIFACTS_WORKDIR:-.}"
115116

116117
if [[ "${COMPRESSED}" == "true" ]]; then
117-
bk_agent "${step_option}" "${build_option}" "${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED}" "${workdir}"
118+
if ! bk_agent "${step_option}" "${build_option}" "${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED}" "${workdir}"; then
119+
handle_bk_error "${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED}"
120+
else
121+
echo "~~~ Uncompressing ${paths[*]} from ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED}"
122+
"${compress[@]}" "${paths[@]}"
118123

119-
echo "~~~ Uncompressing ${paths[*]} from ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED}"
120-
"${compress[@]}" "${paths[@]}"
124+
# single relocation
125+
if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_TO:-}" ]]; then
126+
handle_relocation ""
127+
fi
121128

122-
# single relocation
123-
if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_TO:-}" ]]; then
124-
handle_relocation ""
129+
# multiple relocations
130+
index=0
131+
for path in "${paths[@]}"; do
132+
handle_relocation "${index}"
133+
((index+=1))
134+
done
125135
fi
126136

127-
# multiple relocations
128-
index=0
129-
for path in "${paths[@]}"; do
130-
handle_relocation "${index}"
131-
((index+=1))
132-
done
133-
134137
elif [[ "${SINGULAR_DOWNLOAD_OBJECT}" == "true" ]]; then
135138
if [[ "${RELOCATION}" == "true" ]]; then
136139
source="${BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_FROM}"
137140
else
138141
source="${paths[*]}"
139142
fi
140143

141-
bk_agent "${step_option}" "${build_option}" "${source}" "${workdir}"
142-
143-
if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_TO:-}" ]]; then
144-
handle_relocation ""
144+
if ! bk_agent "${step_option}" "${build_option}" "${source}" "${workdir}"; then
145+
handle_bk_error "${source}"
146+
else
147+
if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_TO:-}" ]]; then
148+
handle_relocation ""
149+
fi
145150
fi
146151
elif [[ "${MULTIPLE_DOWNLOADS}" == "true" ]]; then
147152
index=0
@@ -159,9 +164,12 @@ elif [[ "${MULTIPLE_DOWNLOADS}" == "true" ]]; then
159164
source="${path}"
160165
fi
161166

162-
bk_agent "${!step_env_var:-${step_option}}" "${!build_env_var:-${build_option}}" "${source}" "${workdir}"
167+
if ! bk_agent "${!step_env_var:-${step_option}}" "${!build_env_var:-${build_option}}" "${source}" "${workdir}"; then
168+
handle_bk_error "${source}"
169+
else
170+
handle_relocation "${index}"
171+
fi
163172

164-
handle_relocation "${index}"
165173
((index+=1))
166174
done
167175
fi

tests/download-ignore-missing.bats

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ setup() {
3636
assert_success
3737
assert_output --partial "Downloading artifacts"
3838
assert_output --partial "Ignoring error in download of /tmp/foo.log"
39-
assert_output --partial "Ignoring missing file /tmp/foo.log for relocation"
4039

4140
unstub buildkite-agent
4241
}
@@ -102,7 +101,6 @@ setup() {
102101
assert_success
103102
assert_output --partial "Downloading artifacts"
104103
assert_output --partial "Ignoring error in download of /tmp/foo.log"
105-
assert_output --partial "Ignoring missing file /tmp/foo.log for relocation"
106104
refute_output --partial "download artifact /tmp/foo.log"
107105

108106
assert [ ! -e /tmp/foo2.log ]
@@ -111,7 +109,6 @@ setup() {
111109
unstub buildkite-agent
112110
}
113111

114-
115112
@test "Pre-command downloads multiple > 10 artifacts with build and relocation and some failures" {
116113
stub_calls=()
117114
for i in $(seq 0 10); do
@@ -139,10 +136,9 @@ setup() {
139136
assert [ ! -e /tmp/foo-r-"${i}".log ]
140137
assert [ ! -e /tmp/foo-"${i}".log ]
141138
assert_output --partial "Ignoring error in download of /tmp/foo-${i}.log"
142-
assert_output --partial "Ignoring missing file /tmp/foo-${i}.log"
143139
refute_output --partial "downloaded artifact /tmp/foo-${i}.log"
144140
fi
145141
done
146142

147143
unstub buildkite-agent
148-
}
144+
}

0 commit comments

Comments
 (0)