在Cloud Build CI / CD管道中提出卷曲请求 [英] Make a curl request in Cloud Build CI/CD pipeline

查看:75
本文介绍了在Cloud Build CI / CD管道中提出卷曲请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台服务器,我们的测试用例针对所有API运行,该服务器位于GCP的计算引擎上。如何从云构建CI / CD管道连接它,以便CI / CD阶段仅通过服务器的 200 响应状态代码传递?

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表示要创建自定义生成步骤(此处)。文档不是很清楚

GCP says to create a custom build step (here). Docs are not very clear

推荐答案

您有2个解决方案。


  • 您可以有效地创建自定义步骤。构建一个容器,并通过 ENTRYPOINT 完成该容器,该容器将在Cloud Build管道中调用

  • 您可以在任何内部执行curl调用包含命令的步骤,获取返回代码并对其施加条件(如果相差200,则退出)。这是一个代码示例

  • 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

请注意两个 $$ 防止Cloud Build查看替换变量

Note the double $$ to prevent Cloud Build to look into Substitution variables

这篇关于在Cloud Build CI / CD管道中提出卷曲请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆