From 1edf95f48da4ea759100ee48d14d6139f4ca603e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 9 Jan 2023 19:00:04 -0300 Subject: [PATCH 1/6] Updated docker compose plugin to 4.9.0 --- .buildkite/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 022226e..fe12dd0 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -1,7 +1,7 @@ steps: - label: "🤡 :hammer:" plugins: - - docker-compose#v4.5.0: + - docker-compose#v4.9.0: run: tests - label: ":sparkles: lint" plugins: From 45e0d86dc351f0fb576ad884b178c475da844835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 9 Jan 2023 19:00:25 -0300 Subject: [PATCH 2/6] Updated plugin tester to latest version 4.0.0 --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index d284d01..a90f110 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: '2' services: tests: - image: buildkite/plugin-tester:v3.0.1 + image: buildkite/plugin-tester:v4.0.0 volumes: - ".:/plugin:ro" From 8926e100f44677d06cd7a27a23fcc48301dc04b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 9 Jan 2023 19:07:03 -0300 Subject: [PATCH 3/6] Corrected tests that were missing stub arguments --- tests/download-compressed.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/download-compressed.bats b/tests/download-compressed.bats index 592cfbd..700c28d 100644 --- a/tests/download-compressed.bats +++ b/tests/download-compressed.bats @@ -246,7 +246,7 @@ load '/usr/local/lib/bats/load.bash' "artifact download \* \* : echo downloaded artifact \$3 to \$4" stub unzip \ - "\* \* : echo extracted \$2 from \$1" + "\* \* \* \* : echo extracted \$2, \$3 and \$4 from \$1" run "$PWD/hooks/pre-command" @@ -276,7 +276,7 @@ load '/usr/local/lib/bats/load.bash' "artifact download \* \* : echo downloaded artifact \$3 to \$4" stub tar \ - "xzf \* \* : echo extracted \$3 from \$2" + "xzf \* \* \* \* : echo extracted \$3, \$4 and \$5 from \$2" run "$PWD/hooks/pre-command" From 17f7dfdce43a8dbecdeda7f62348c0fcbeef21e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 9 Jan 2023 19:35:31 -0300 Subject: [PATCH 4/6] Added new option to skip uploads --- hooks/post-command | 9 +++++++++ plugin.yml | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/hooks/post-command b/hooks/post-command index 8200cf5..a693d3f 100755 --- a/hooks/post-command +++ b/hooks/post-command @@ -6,6 +6,15 @@ if [[ "${BUILDKITE_PLUGIN_ARTIFACTS_DEBUG:-false}" =~ (true|on|1) ]] ; then set -x fi +while IFS='=' read -r EXIT_VAR _ ; do + if [[ $EXIT_VAR =~ ^(BUILDKITE_PLUGIN_ARTIFACTS_SKIP_ON_STATUS(|_[0-9]+))$ ]]; then + if [ "${BUILDKITE_COMMAND_EXIT_STATUS}" -eq "${!EXIT_VAR}" ]; then + echo "Command exit status matches ${!EXIT_VAR}, skipping upload" + exit 0 + fi + fi +done < <(env | sort) + args=("upload") if [[ -n "${BUILDKITE_PLUGIN_ARTIFACTS_JOB:-}" ]] ; then diff --git a/plugin.yml b/plugin.yml index 4d85eb9..3298bca 100644 --- a/plugin.yml +++ b/plugin.yml @@ -53,9 +53,17 @@ configuration: pattern: '.*(.zip|.tgz)$' ignore-missing: type: boolean + skip-on-status: + oneOf: + - type: integer + - type: array + items: + type: integer oneOf: - required: - upload - required: - download + dependencies: + skip-on-status: [ upload ] additionalProperties: false From da9c0f12da0fb8f71e62458b640d79b334df1938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 9 Jan 2023 19:36:25 -0300 Subject: [PATCH 5/6] Added documentation and tests --- README.md | 30 ++++++++++++++++++++++++ tests/upload.bats | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/README.md b/README.md index 72b3a25..deb1d6b 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,36 @@ steps: 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. +### `skip-on-status` (optional, integer or array of integers, uploads only) + +You can set this to the exit codes or array of exit codes of the command step (as defined by the `BUILDKITE_COMMAND_EXIT_STATUS` variable) that will cause the plugin to avoid trying to upload artifacts. + +This should allow you to specify known failure conditions that you want to avoid uploading artifacts. For example, because you know logs will be huge or not useful. + +Skip uploading if the main command failed with exit code 147: + +```yml +steps: + - command: ... + plugins: + - artifacts#v1.8.0: + upload: "log/*.log" + skip-on-status: 147 +``` + +Alternatively, skip artifact uploading on exit codes 1 and 5: + +```yml +steps: + - command: ... + plugins: + - artifacts#v1.8.0: + upload: "log/*.log" + skip-on-status: + - 1 + - 5 +``` + ## Developing To run testing, shellchecks and plugin linting use use `bk run` with the [Buildkite CLI](https://github.com/buildkite/cli). diff --git a/tests/upload.bats b/tests/upload.bats index b20f125..b844bd0 100644 --- a/tests/upload.bats +++ b/tests/upload.bats @@ -222,4 +222,64 @@ load '/usr/local/lib/bats/load.bash' unset BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_TO unset BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_0_FROM unset BUILDKITE_PLUGIN_ARTIFACTS_DOWNLOAD_0_TO +} + +@test "Single skip exit status does not match still uploads" { + export BUILDKITE_COMMAND_EXIT_STATUS="100" + export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="*.log" + export BUILDKITE_PLUGIN_ARTIFACTS_SKIP_ON_STATUS="10" + + stub buildkite-agent \ + "artifact upload \* : echo uploaded \$3" + + run "$PWD/hooks/post-command" + + assert_success + assert_output --partial "Uploading artifacts" + + unstub buildkite-agent +} + +@test "Single skip exit status matches, skips upload" { + export BUILDKITE_COMMAND_EXIT_STATUS="10" + export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="*.log" + export BUILDKITE_PLUGIN_ARTIFACTS_SKIP_ON_STATUS="10" + + run "$PWD/hooks/post-command" + + assert_success + refute_output --partial "Uploading artifacts" + assert_output --partial "skipping upload" +} + +@test "Multiple skip exit status does not match still uploads" { + export BUILDKITE_COMMAND_EXIT_STATUS="100" + export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="*.log" + export BUILDKITE_PLUGIN_ARTIFACTS_SKIP_ON_STATUS_0="10" + export BUILDKITE_PLUGIN_ARTIFACTS_SKIP_ON_STATUS_1="1" + + stub buildkite-agent \ + "artifact upload \* : echo uploaded \$3" + + run "$PWD/hooks/post-command" + + assert_success + assert_output --partial "Uploading artifacts" + + unstub buildkite-agent +} + +@test "Multiple skip exit status matches, skips upload" { + export BUILDKITE_COMMAND_EXIT_STATUS="10" + export BUILDKITE_PLUGIN_ARTIFACTS_UPLOAD="*.log" + export BUILDKITE_PLUGIN_ARTIFACTS_SKIP_ON_STATUS_0="1" + export BUILDKITE_PLUGIN_ARTIFACTS_SKIP_ON_STATUS_1="100" + export BUILDKITE_PLUGIN_ARTIFACTS_SKIP_ON_STATUS_2="10" + export BUILDKITE_PLUGIN_ARTIFACTS_SKIP_ON_STATUS_3="2" + + run "$PWD/hooks/post-command" + + assert_success + refute_output --partial "Uploading artifacts" + assert_output --partial "skipping upload" } \ No newline at end of file From 7af505cc008e926118342b2ff1d584b84bac9132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= Date: Mon, 9 Jan 2023 19:37:23 -0300 Subject: [PATCH 6/6] Updated version to next value --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index deb1d6b..fed6867 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This functionality duplicates the [artifact_paths](https://buildkite.com/docs/pi steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: upload: "log/**/*.log" ``` @@ -20,7 +20,7 @@ You can specify multiple files/globs to upload as artifacts: steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: upload: [ "log/**/*.log", "debug/*.error" ] ``` @@ -30,7 +30,7 @@ And even rename them before uploading them (can not use globs here though, sorry steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: upload: - from: log1.log to: log2.log @@ -47,7 +47,7 @@ eg: uploading a public file when using S3 steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: upload: "coverage-report/**/*" s3-upload-acl: public-read ``` @@ -57,7 +57,7 @@ eg: uploading a private file when using GS steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: upload: "coverage-report/**/*" gs-upload-acl: private ``` @@ -70,7 +70,7 @@ This downloads artifacts matching globs to the local filesystem. See [downloadin steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: download: "log/**/*.log" ``` @@ -80,7 +80,7 @@ You can specify multiple files/patterns: steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: download: [ "log/**/*.log", "debug/*.error" ] ``` @@ -90,7 +90,7 @@ Rename particular files after downloading them: steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: download: - from: log1.log to: log2.log @@ -102,7 +102,7 @@ And even do so from different builds/steps: steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: step: UUID-DEFAULT build: UUID-DEFAULT-2 download: @@ -144,7 +144,7 @@ When uploading, globs specified in the `upload` option will be compressed in a s steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: upload: "log/*.log" compressed: logs.zip ``` @@ -155,7 +155,7 @@ When downloading, this option states the actual name of the artifact to be downl steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: download: "log/*.log" compressed: logs.tgz ``` @@ -176,7 +176,7 @@ Skip uploading if the main command failed with exit code 147: steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: upload: "log/*.log" skip-on-status: 147 ``` @@ -187,7 +187,7 @@ Alternatively, skip artifact uploading on exit codes 1 and 5: steps: - command: ... plugins: - - artifacts#v1.8.0: + - artifacts#v1.9.0: upload: "log/*.log" skip-on-status: - 1