I've created a Docker file and configured it as the trigger to my Google Cloud Source Repository. There are only a few options available to I chose "Push to a branch". Right now my docker image can do a new Cloud Function (written with golang) deployment upon a new push. I have added a go test step in my Docker file. I want to reject the commit if it will cause the go test failed, like GitLab. If the go test fails, the cloud function won't be updated. But the bad code will stay there. How to implement this "reject failure code" feature to Google Cloud Source Repository?
This is not a complete or sufficient answer, but it's too long for a comment and the snippet needs formatting.
I suspect you have a build file you can edit somewhere called cloudbuild.yaml
, in which you can add in a test step.
We use Github for our repos with the GCP plugin. Though different from Google's source repository, we typically control this by adding a step in our cloudbuild.yaml
file, e.g.
# build and run the test suite
- name: 'python:3.8-slim' # add a go container here, see below
id: 'Run Unit Tests'
entrypoint: '/bin/bash'
args:
- "-c"
- "\
whattevercommandsyouwant && \
morecommands"
That's not complete but hopefully it helps you solve the issue. And for your reference, the Google Cloud Build Go docs.