@@ -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
7980handle_relocation () {
114115workdir=" ${BUILDKITE_PLUGIN_ARTIFACTS_WORKDIR:- .} "
115116
116117if [[ " ${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-
134137elif [[ " ${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
146151elif [[ " ${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
167175fi
0 commit comments