@@ -6,6 +6,19 @@ if [[ "${BUILDKITE_PLUGIN_ARTIFACTS_DEBUG:-false}" =~ (true|on|1) ]] ; then
66 set -x
77fi
88
9+
10+ # expand variables in the variable name referenced
11+ # DANGEROUS due to the use of eval
12+ # assumes that the environment variable name exists
13+ expand_vars () {
14+ if [[ ${BUILDKITE_PLUGIN_ARTIFACTS_EXPAND_UPLOAD_VARS:- false} != " false" ]]; then
15+ # expand the variable
16+ eval echo " ${! 1} "
17+ else
18+ echo " ${! 1} "
19+ fi
20+ }
21+
922while IFS=' =' read -r EXIT_VAR _ ; do
1023 if [[ $EXIT_VAR =~ ^(BUILDKITE_PLUGIN_ARTIFACTS_SKIP_ON_STATUS(| _[0-9]+))$ ]]; then
1124 if [ " ${BUILDKITE_COMMAND_EXIT_STATUS} " -eq " ${! EXIT_VAR} " ]; then
@@ -55,9 +68,9 @@ if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED:-}" ]]; then
5568 COMPRESSED=" true"
5669
5770 if [[ " ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED} " =~ .* \. zip ]]; then
58- compress+=(" zip" " -r" " ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED} " )
71+ compress+=(" zip" " -r" )
5972 elif [[ " ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED} " =~ .* \. tgz ]]; then
60- compress+=(" tar" " czf" " ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED} " )
73+ compress+=(" tar" " czf" )
6174 else
6275 echo " +++ 🚨 The inferred compression file format for the artifact is not currently supported"
6376 exit 1
@@ -91,11 +104,14 @@ handle_relocation() {
91104 dest_env_var=" BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_${var_string} TO"
92105
93106 if [[ -n " ${! source_env_var:- } " ]] && [[ -n " ${! dest_env_var:- } " ]]; then
94- if [[ -e ${! source_env_var} ]]; then
95- echo " ~~~ Moving [${! source_env_var} ] to [${! dest_env_var} ]..."
96- mv " ${! source_env_var} " " ${! dest_env_var} "
107+ SOURCE_FILE=" $( expand_vars " ${source_env_var} " ) "
108+ DEST_FILE=" $( expand_vars " ${dest_env_var} " ) "
109+
110+ if [[ -e " ${SOURCE_FILE} " ]]; then
111+ echo " ~~~ Moving [${SOURCE_FILE} ] to [${DEST_FILE} ]..."
112+ mv " ${SOURCE_FILE} " " ${DEST_FILE} "
97113 elif [[ ${BUILDKITE_PLUGIN_ARTIFACTS_IGNORE_MISSING:- " false" } == " true" ]]; then
98- echo " Ignoring missing file ${! source_env_var } for relocation"
114+ echo " Ignoring missing file ${SOURCE_FILE } for relocation"
99115 fi
100116 fi
101117}
121137if [[ " ${SINGULAR_UPLOAD_OBJECT} " == " true" ]]; then
122138 if [[ " ${RELOCATION} " == " true" ]]; then
123139 handle_relocation " "
124- path=" ${ BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_TO} "
140+ path=" $( expand_vars BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_TO) "
125141 else
126- path=" ${paths[0]} "
142+ export FILENAME=" ${paths[0]} "
143+ path=" $( expand_vars FILENAME) "
127144 fi
128145
129146 if [[ " ${COMPRESSED} " == " true" ]]; then
130- echo " ~~~ Compressing ${path} to ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED} "
147+ COMPRESSED_FILENAME=" $( expand_vars BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED) "
148+ echo " ~~~ Compressing ${path} to ${COMPRESSED_FILENAME} "
131149 if [[ ! -e " ${path} " ]]; then
132150 echo " +++ 🚨 Unable to compress artifact, '${path} ' may not exist or is an empty directory"
133151 else
134- " ${compress[@]} " " ${path} "
135- path=" ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED }"
152+ " ${compress[@]} " " ${COMPRESSED_FILENAME} " " ${ path}"
153+ path=" ${COMPRESSED_FILENAME }"
136154 fi
137155 fi
138156
139157 echo " ~~~ Uploading artifacts ${EXTRA_MESSAGE} "
140158 bk_agent " ${args[@]} " " ${path} "
141159elif [[ " ${COMPRESSED} " == " true" ]]; then
160+ COMPRESSED_FILENAME=" $( expand_vars BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED) "
142161 final_paths=()
143162 index=0
144163 for path in " ${paths[@]} " ; do
145164 handle_relocation " ${index} "
146165 dest_env_var=" BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_${index} _TO"
147166 if [[ -n " ${! dest_env_var:- } " ]]; then
148- path=" ${! dest_env_var} "
167+ path=" $( expand_vars " ${dest_env_var} " ) "
168+ else
169+ path=" $( expand_vars path) "
149170 fi
150171
151172 final_paths+=(" $path " )
152173 (( index+= 1 ))
153174 done
154175
155- echo " ~~~ Compressing ${final_paths[*]} to ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED } "
176+ echo " ~~~ Compressing ${final_paths[*]} to ${COMPRESSED_FILENAME } "
156177 " ${compress[@]} " " ${final_paths[@]} "
157178
158179 echo " ~~~ Uploading artifacts ${EXTRA_MESSAGE} "
159- bk_agent " ${args[@]} " " ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED } "
180+ bk_agent " ${args[@]} " " ${COMPRESSED_FILENAME } "
160181elif [[ " ${MULTIPLE_UPLOADS} " == " true" ]]; then
161182 index=0
162183 echo " ~~~ Uploading artifacts ${EXTRA_MESSAGE} "
@@ -165,7 +186,9 @@ elif [[ "${MULTIPLE_UPLOADS}" == "true" ]]; then
165186 handle_relocation " ${index} "
166187 dest_env_var=" BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_${index} _TO"
167188 if [[ -n " ${! dest_env_var:- } " ]]; then
168- path=" ${! dest_env_var} "
189+ path=" $( expand_vars " ${dest_env_var} " ) "
190+ else
191+ path=" $( expand_vars path) "
169192 fi
170193
171194 bk_agent " ${args[@]} " " $path "
0 commit comments