Is it possible in some manner to gracefully exit/break in some middle step of GCB?
If some step command exits with non success code, build flow will break, but will also be considered failed. I'd like to break but maintain a success status.
Is it possible in some manner to gracefully exit/break in some middle step of GCB?
If some step command exits with non success code, build flow will break, but will also be considered failed. I'd like to break but maintain a success status.
I found a solution which I consider a better workaround: let the build cancel itself using gcloud sdk.
- name: 'gcr.io/cloud-builders/gcloud'
id: 'Cancel current build if on master'
entrypoint: 'sh'
args:
- '-c'
- |
test $BRANCH_NAME = "master" && gcloud builds cancel $BUILD_ID > /dev/null || true
Note the service account that runs the builds (xxx@cloudbuild.gserviceaccount.com
) should have appropriate permissions to cancel build.
That's something which is not possible at the moment (even though it's an option that will be added in the future), but you can use a workaround to ignore the failure of any step. Using bash you achieve that by using something like the following:
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker pull gcr.io/$PROJECT_ID/my-image || exit 0
Here you can find the link to the Github issue where the same question was addressed and you will be able to find more information.