Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Artifacts From a Failed Build

I am running some screen diffing tests in one of my Cloud Build steps. The tests produce png files that I would like to view after the build, but it appears to upload artifacts on successful builds.

If my test fail, the process exits with a non-zero code, which results in this error:

ERROR: build step 0 "gcr.io/k8s-skaffold/skaffold" failed: step exited with non-zero status: 1

Which further results in another error


ERROR: (gcloud.builds.submit) build a22d1ab5-c996-49fe-a782-a74481ad5c2a completed with status "FAILURE"

And no artifacts get uploaded.

I added || true after my tests, so it exits successfully, and the artifacts get uploaded.

I want to:

  • A) Confirm that this behavior is expected
  • B) Know if there is a way to upload artifacts even if a step fails

Edit:

Here is my cloudbuild.yaml


options:
 machineType: 'N1_HIGHCPU_32'

timeout: 3000s

steps:

- name: 'gcr.io/k8s-skaffold/skaffold'
  env:
  - 'CLOUD_BUILD=1'
  entrypoint: bash
  args:
  - -x  # print commands as they are being executed
  - -c  # run the following command...
  - build/test/smoke/smoke-test.sh


artifacts:
  objects:
    location: 'gs://cloudbuild-artifacts/$BUILD_ID'
    paths: [
      '/workspace/build/test/cypress/screenshots/*.png'
    ]
like image 259
Lee Gaines Avatar asked Oct 29 '25 15:10

Lee Gaines


1 Answers

Google Cloud Build doesn't allow us to upload artifacts (or run some steps ) if a build step fails. This is the expected behavior.

There is an already feature request created in Public Issue Tracker to allow us to run some steps even though the build has finished or failed. Please feel free to star it to get all the related updates on this issue.

A workaround per now is as you mentioned using || true after the tests or use || exit 0 as mentioned in this Github issue.

like image 170
Nibrass H Avatar answered Oct 31 '25 11:10

Nibrass H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!