Skip to content

Commit 030a835

Browse files
HugeIRLpzeballos
andauthored
SUP-1372 fix compressed when ignore-missing is set (#91)
* Updated README.md version numbers * Removed compression expression wrap * Updated compression test, add new compression ignore-missing test * Removed mocked glob pathing in upload compressed tests * Add clarification when using compressed with ignore-missing * Update test title --------- Co-authored-by: Pol (Paula) <pzeballos@users.noreply.github.com>
1 parent 9c64bcb commit 030a835

3 files changed

Lines changed: 95 additions & 27 deletions

File tree

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This functionality duplicates the [artifact_paths](https://buildkite.com/docs/pi
1010
steps:
1111
- command: ...
1212
plugins:
13-
- artifacts#v1.9.0:
13+
- artifacts#v1.9.1:
1414
upload: "log/**/*.log"
1515
```
1616
@@ -20,7 +20,7 @@ You can specify multiple files/globs to upload as artifacts:
2020
steps:
2121
- command: ...
2222
plugins:
23-
- artifacts#v1.9.0:
23+
- artifacts#v1.9.1:
2424
upload: [ "log/**/*.log", "debug/*.error" ]
2525
```
2626
@@ -30,7 +30,7 @@ And even rename them before uploading them (can not use globs here though, sorry
3030
steps:
3131
- command: ...
3232
plugins:
33-
- artifacts#v1.9.0:
33+
- artifacts#v1.9.1:
3434
upload:
3535
- from: log1.log
3636
to: log2.log
@@ -47,7 +47,7 @@ eg: uploading a public file when using S3
4747
steps:
4848
- command: ...
4949
plugins:
50-
- artifacts#v1.9.0:
50+
- artifacts#v1.9.1:
5151
upload: "coverage-report/**/*"
5252
s3-upload-acl: public-read
5353
```
@@ -57,7 +57,7 @@ eg: uploading a private file when using GS
5757
steps:
5858
- command: ...
5959
plugins:
60-
- artifacts#v1.9.0:
60+
- artifacts#v1.9.1:
6161
upload: "coverage-report/**/*"
6262
gs-upload-acl: private
6363
```
@@ -70,7 +70,7 @@ This downloads artifacts matching globs to the local filesystem. See [downloadin
7070
steps:
7171
- command: ...
7272
plugins:
73-
- artifacts#v1.9.0:
73+
- artifacts#v1.9.1:
7474
download: "log/**/*.log"
7575
```
7676
@@ -80,7 +80,7 @@ You can specify multiple files/patterns:
8080
steps:
8181
- command: ...
8282
plugins:
83-
- artifacts#v1.9.0:
83+
- artifacts#v1.9.1:
8484
download: [ "log/**/*.log", "debug/*.error" ]
8585
```
8686
@@ -90,7 +90,7 @@ Rename particular files after downloading them:
9090
steps:
9191
- command: ...
9292
plugins:
93-
- artifacts#v1.9.0:
93+
- artifacts#v1.9.1:
9494
download:
9595
- from: log1.log
9696
to: log2.log
@@ -102,7 +102,7 @@ And even do so from different builds/steps:
102102
steps:
103103
- command: ...
104104
plugins:
105-
- artifacts#v1.9.0:
105+
- artifacts#v1.9.1:
106106
step: UUID-DEFAULT
107107
build: UUID-DEFAULT-2
108108
download:
@@ -145,7 +145,7 @@ When uploading, the file or directory specified in the `upload` option will be c
145145
steps:
146146
- command: ...
147147
plugins:
148-
- artifacts#v1.9.0:
148+
- artifacts#v1.9.1:
149149
upload: "log/my-folder"
150150
compressed: logs.zip
151151
```
@@ -156,14 +156,14 @@ When downloading, this option states the actual name of the artifact to be downl
156156
steps:
157157
- command: ...
158158
plugins:
159-
- artifacts#v1.9.0:
159+
- artifacts#v1.9.1:
160160
download: "log/file.log"
161161
compressed: logs.tgz
162162
```
163163

164164
### `ignore-missing` (optional, boolean)
165165

166-
If set to `true`, it will ignore errors caused when calling `buildkite-agent artifact` to prevent failures if you expect artifacts not to be present in some situations.
166+
If set to `true`, it will ignore errors caused when calling `buildkite-agent artifact` to prevent failures if you expect artifacts not to be present in some situations. When using the `compressed` property, it will ignore compressing the artifacts that are not present.
167167

168168
### `skip-on-status` (optional, integer or array of integers, uploads only)
169169

@@ -177,7 +177,7 @@ Skip uploading if the main command failed with exit code 147:
177177
steps:
178178
- command: ...
179179
plugins:
180-
- artifacts#v1.9.0:
180+
- artifacts#v1.9.1:
181181
upload: "log/*.log"
182182
skip-on-status: 147
183183
```
@@ -188,7 +188,7 @@ Alternatively, skip artifact uploading on exit codes 1 and 5:
188188
steps:
189189
- command: ...
190190
plugins:
191-
- artifacts#v1.9.0:
191+
- artifacts#v1.9.1:
192192
upload: "log/*.log"
193193
skip-on-status:
194194
- 1

hooks/post-command

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ if [[ "${SINGULAR_UPLOAD_OBJECT}" == "true" ]]; then
128128

129129
if [[ "${COMPRESSED}" == "true" ]]; then
130130
echo "~~~ Compressing ${path} to ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED}"
131-
"${compress[@]}" "${path}"
132-
path=" ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED}"
131+
if [[ ! -e "${path}" ]]; then
132+
echo "+++ 🚨 Unable to compress artifact, '${path}' may not exist or is an empty directory"
133+
else
134+
"${compress[@]}" "${path}"
135+
path=" ${BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED}"
136+
fi
133137
fi
134138

135139
echo "~~~ Uploading artifacts ${EXTRA_MESSAGE}"

tests/upload-compressed.bats

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@ load "${BATS_PLUGIN_PATH}/load.bash"
55
# Uncomment to enable stub debug output:
66
# export BUILDKITE_AGENT_STUB_DEBUG=/dev/tty
77

8+
@test "Compression fails when there is nothing to compress" {
9+
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="non_existent_file.txt"
10+
export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED="file.zip"
11+
12+
run "$PWD/hooks/post-command"
13+
14+
assert_failure
15+
assert_output --partial "Unable to compress artifact, 'non_existent_file.txt' may not exist or is an empty directory"
16+
17+
unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD
18+
unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
19+
}
20+
21+
@test "Compression ignored when there is nothing to compress and ignore-missing is set to true" {
22+
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="non_existent_file.txt"
23+
export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED="file.zip"
24+
export BUILDKITE_PLUGIN_ARTIFACTS_IGNORE_MISSING="true"
25+
26+
run "$PWD/hooks/post-command"
27+
28+
assert_success
29+
assert_output --partial "Unable to compress artifact, 'non_existent_file.txt' may not exist or is an empty directory"
30+
assert_output --partial "Ignoring error in upload of"
31+
32+
unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD
33+
unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
34+
}
35+
836
@test "Invalid compressed format" {
937
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="file.log"
1038
export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED="file.rar"
@@ -20,9 +48,11 @@ load "${BATS_PLUGIN_PATH}/load.bash"
2048
}
2149

2250
@test "Single value zip" {
23-
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="*.log"
51+
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="file.log"
2452
export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED="file.zip"
2553

54+
touch "file.log"
55+
2656
stub buildkite-agent \
2757
"artifact upload \* : echo uploaded \$3"
2858

@@ -32,7 +62,7 @@ load "${BATS_PLUGIN_PATH}/load.bash"
3262
run "$PWD/hooks/post-command"
3363

3464
assert_success
35-
assert_output --partial "Compressing *.log to file.zip"
65+
assert_output --partial "Compressing file.log to file.zip"
3666
assert_output --partial "Uploading artifacts"
3767
assert_output --partial "uploaded file.zip"
3868

@@ -41,12 +71,16 @@ load "${BATS_PLUGIN_PATH}/load.bash"
4171

4272
unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD
4373
unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
74+
75+
rm "file.log"
4476
}
4577

4678
@test "Single value tgz" {
47-
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="*.log"
79+
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="file.log"
4880
export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED="file.tgz"
4981

82+
touch "file.log"
83+
5084
stub buildkite-agent \
5185
"artifact upload \* : echo uploaded \$3"
5286

@@ -56,7 +90,7 @@ load "${BATS_PLUGIN_PATH}/load.bash"
5690
run "$PWD/hooks/post-command"
5791

5892
assert_success
59-
assert_output --partial "Compressing *.log to file.tgz"
93+
assert_output --partial "Compressing file.log to file.tgz"
6094
assert_output --partial "Uploading artifacts"
6195
assert_output --partial "uploaded file.tgz"
6296

@@ -65,6 +99,8 @@ load "${BATS_PLUGIN_PATH}/load.bash"
6599

66100
unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD
67101
unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
102+
103+
rm "file.log"
68104
}
69105

70106
@test "Single file zip with relocation" {
@@ -138,10 +174,12 @@ load "${BATS_PLUGIN_PATH}/load.bash"
138174
}
139175

140176
@test "Single value zip with job" {
141-
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="*.log"
177+
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="file.log"
142178
export BUILDKITE_PLUGIN_ARTIFACTS_JOB="12345"
143179
export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED="file.zip"
144180

181+
touch "file.log"
182+
145183
stub buildkite-agent \
146184
"artifact upload --job \* \* : echo uploaded \$5 with --job \$4"
147185

@@ -152,23 +190,27 @@ load "${BATS_PLUGIN_PATH}/load.bash"
152190

153191
assert_success
154192
assert_output --partial "Uploading artifacts (extra args: '--job 12345')"
155-
assert_output --partial "Compressing *.log to file.zip"
193+
assert_output --partial "Compressing file.log to file.zip"
156194
assert_output --partial "uploaded file.zip"
157-
refute_output --partial "uploaded *.log"
195+
refute_output --partial "uploaded file.log"
158196

159197
unstub buildkite-agent
160198
unstub zip
161199

162200
unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD
163201
unset BUILDKITE_PLUGIN_ARTIFACTS_JOB
164202
unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
203+
204+
rm "file.log"
165205
}
166206

167207
@test "Single value tgz with job" {
168-
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="*.log"
208+
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="file.log"
169209
export BUILDKITE_PLUGIN_ARTIFACTS_JOB="12345"
170210
export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED="file.tgz"
171211

212+
touch "file.log"
213+
172214
stub buildkite-agent \
173215
"artifact upload --job \* \* : echo uploaded \$5 with --job \$4"
174216

@@ -179,16 +221,18 @@ load "${BATS_PLUGIN_PATH}/load.bash"
179221

180222
assert_success
181223
assert_output --partial "Uploading artifacts (extra args: '--job 12345')"
182-
assert_output --partial "Compressing *.log to file.tgz"
224+
assert_output --partial "Compressing file.log to file.tgz"
183225
assert_output --partial "uploaded file.tgz"
184-
refute_output --partial "uploaded *.log"
226+
refute_output --partial "uploaded file.log"
185227

186228
unstub buildkite-agent
187229
unstub tar
188230

189231
unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD
190232
unset BUILDKITE_PLUGIN_ARTIFACTS_JOB
191233
unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
234+
235+
rm "file.log"
192236
}
193237

194238
@test "Multiple artifacts zip" {
@@ -197,6 +241,10 @@ load "${BATS_PLUGIN_PATH}/load.bash"
197241
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_2="baz.log"
198242
export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED="file.zip"
199243

244+
touch /tmp/foo.log
245+
touch bar.log
246+
touch baz.log
247+
200248
stub buildkite-agent \
201249
"artifact upload \* : echo uploaded \$3"
202250

@@ -220,6 +268,10 @@ load "${BATS_PLUGIN_PATH}/load.bash"
220268
unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_1
221269
unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_2
222270
unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
271+
272+
rm /tmp/foo.log
273+
rm bar.log
274+
rm baz.log
223275
}
224276

225277
@test "Multiple artifacts tgz" {
@@ -228,6 +280,10 @@ load "${BATS_PLUGIN_PATH}/load.bash"
228280
export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_2="baz.log"
229281
export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED="file.tgz"
230282

283+
touch /tmp/foo.log
284+
touch bar.log
285+
touch baz.log
286+
231287
stub buildkite-agent \
232288
"artifact upload \* : echo uploaded \$3"
233289

@@ -251,6 +307,10 @@ load "${BATS_PLUGIN_PATH}/load.bash"
251307
unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_1
252308
unset BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD_2
253309
unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
310+
311+
rm /tmp/foo.log
312+
rm bar.log
313+
rm baz.log
254314
}
255315

256316
@test "Multiple artifacs zip some relocation" {
@@ -261,6 +321,8 @@ load "${BATS_PLUGIN_PATH}/load.bash"
261321
export BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED="file.zip"
262322

263323
touch /tmp/foo.log
324+
touch bar.log
325+
touch baz.log
264326

265327
stub buildkite-agent \
266328
"artifact upload \* : echo uploaded \$3"
@@ -282,6 +344,8 @@ load "${BATS_PLUGIN_PATH}/load.bash"
282344
assert [ -e /tmp/foo2.log ]
283345
assert [ ! -e /tmp/foo.log ]
284346
rm /tmp/foo2.log
347+
rm bar.log
348+
rm baz.log
285349

286350
unstub buildkite-agent
287351
unstub zip
@@ -365,4 +429,4 @@ load "${BATS_PLUGIN_PATH}/load.bash"
365429
unset BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_0_FROM
366430
unset BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_0_TO
367431
unset BUILDKITE_PLUGIN_ARTIFACTS_COMPRESSED
368-
}
432+
}

0 commit comments

Comments
 (0)