问题
I have a server where our test cases run for all API, which is on the compute engine of GCP. How can I connect it from cloud build CI/CD pipeline so that the CI/CD stage passes only on 200 response status code from the server?
GCP says to create a custom build step (here). Docs are not very clear
回答1:
You have 2 solutions.
- You can effectively create a custom step. Build a container, finish it by an
ENTRYPOINT
which will be invoked in the Cloud Build pipeline - You can perform a curl call inside any steps which contain the command, get the return code and apply a condition on it (here exit if different of 200). Here an example of code
steps:
- name: gcr.io/cloud-builders/gcloud
entrypoint: "bash"
args:
- "-c"
- |
RESPONSE=$(curl -i <YOUR URL> | grep HTTP | cut -d' ' -f2)
if [ "200" != "$$RESPONSE" ]; then exit 1; fi
Note the double $$
to prevent Cloud Build to look into Substitution variables
来源:https://stackoverflow.com/questions/58570335/make-a-curl-request-in-cloud-build-ci-cd-pipeline