Make a curl request in Cloud Build CI/CD pipeline

别等时光非礼了梦想. 提交于 2020-01-25 08:52:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!