在GCP cloudbuild.yaml中添加“您确定..."对话框 [英] Adding a “Are you sure …” dialog in GCP cloudbuild.yaml
问题描述
基本上,我想在cloudbuild.yaml
中的步骤2(run_test_test-coverage)之前添加"Are you sure you want to run unit tests ?"
对话框.我怎样才能做到这一点 ?这可以在詹金斯中完成,但不知道如何在GCP cloudbuild中完成.
Basically, I want to add a "Are you sure you want to run unit tests ?"
dialog before step 2(run_test_test-coverage) in my cloudbuild.yaml
. How can I do that ? This can be done in jenkins but don't know how to do the same in GCP cloudbuild.
cloudbuild.yaml
cloudbuild.yaml
steps:
- name: 'node:10.10.0'
id: installing_npm
args: ['npm', 'install']
dir: 'API/system_performance'
- name: 'node:10.10.0'
id: run_test_test-coverage
args: ['npm', 'run', 'coverage']
dir: 'API/system_performance'
以下是我更新的cloudbuild.yaml文件:
Below is my updated cloudbuild.yaml file:
- name: 'node:10.10.0'
id: installing_npm
args: ['npm', 'install']
dir: 'API/groups'
- name: 'gcr.io/cloud-builders/gcloud'
id: deploy
dir: '/workspace/API/groups'
entrypoint: bash
args:
- '-c'
- |
if [ $BRANCH_NAME != "xoxoxoxox" ]
then
gcloud functions deploy groups &&\
--region=us-central1 &&\
--source=. &&\
--trigger-http &&\
--runtime=nodejs8 &&\
--entry-point=App &&\
--allow-unauthenticated &&\
--service-account=xoxoxxooxox@appspot.gserviceaccount.com
fi
在这里,我认为构建成功,但是当条件变为false时,尽管构建成功部署,但是我得到了以下输出,并且构建失败.为什么这样?
Here, I get the build as successful, but when the condition becomes false, although build gets deployed successfully, yet I get the below output and the the build gets failed. Why so ?
Finished Step #0 - "installing_npm"
Starting Step #1 - "deploy"
Step #1 - "deploy": Already have image (with digest): gcr.io/cloud-builders/gcloud
Step #1 - "deploy": Created .gcloudignore file. See `gcloud topic gcloudignore` for details.
Step #1 - "deploy": Deploying function (may take a while - up to 2 minutes)...
Step #1 - "deploy": .....................done.
Step #1 - "deploy": availableMemoryMb: 256
Step #1 - "deploy": entryPoint: App
Step #1 - "deploy": httpsTrigger:
Step #1 - "deploy": url: https://xoxoxoxo.cloudfunctions.net/groups
Step #1 - "deploy": ingressSettings: ALLOW_ALL
Step #1 - "deploy": labels:
Step #1 - "deploy": deployment-tool: cli-gcloud
Step #1 - "deploy": name: projects/xoxoxoxo/locations/us-central1/functions/groups
Step #1 - "deploy": runtime: nodejs8
Step #1 - "deploy": serviceAccountEmail: xoxoxoxo@appspot.gserviceaccount.com
Step #1 - "deploy": sourceUploadUrl: https://storage.googleapis.com/xoxoxo
Step #1 - "deploy": status: ACTIVE
Step #1 - "deploy": timeout: 60s
Step #1 - "deploy": updateTime: '2020-05-25T19:18:26.099Z'
Step #1 - "deploy": versionId: '12'
Step #1 - "deploy": bash: line 2: : command not found
Step #1 - "deploy": bash: line 3: --region=us-central1: command not found
Step #1 - "deploy": bash: line 6: --runtime=nodejs8: command not found
Step #1 - "deploy": bash: line 7: --entry-point=App: command not found
Step #1 - "deploy": bash: line 8: --allow-unauthenticated: command not found
Finished Step #1 - "deploy"
ERROR
ERROR: build step 1 "gcr.io/cloud-builders/gcloud" failed: step exited with non-zero status: 127
推荐答案
您无法与Cloud Build进行交互.实际上,您将文件发送到CI,然后等待结果,而已.
You can't interact with Cloud Build. In fact, you send the file to a CI, and you wait for the result, no more.
但是,您可以自定义步骤.我回答了关于条件步骤的此问题.使用替代变量来运行构建有或没有测试.
But, you can customize the steps. I answered this question about the conditional step. Use a substitution variable for running your build with, or without the tests.
选择不会是交互式的,但是在构建提交时,您可以选择.
The choice won't be interactive, but at the build submission, you can have the choice.
->我的意思是,当您提交构建时,例如手动提交
-> I mean that when you submit the build, for example manually
gcloud build submit --substitions=_SKIPTEST=true
您选择在提交时跳过测试,而不是在构建过程中跳过测试.
You choose to skip the tests at the submission, not during the build.
编辑
执行bash -c |
时,请想象您在linux终端上,并按顺序逐行输入命令.对于多行,请添加反斜杠\
.在这里&&
是没有用的.将它用于链接命令,但是这里没有用,因为您按顺序执行命令.
When you perform a bash -c |
imagine that you are on your linux terminal and enter line by line your commands in sequence. For multiline, add backslash \
. Here the &&
are useless. Use it for chaining command, but here it's useless because you execute command in sequence.
所以这里是正确的交换
- name: 'gcr.io/cloud-builders/gcloud'
id: deploy
dir: '/workspace/API/groups'
entrypoint: bash
args:
- '-c'
- |
if [ $BRANCH_NAME != "xoxoxoxox" ]
then
gcloud functions deploy groups \
--region=us-central1 \
--source=. \
--trigger-http \
--runtime=nodejs8 \
--entry-point=App \
--allow-unauthenticated \
--service-account=xoxoxxooxox@appspot.gserviceaccount.com
fi
这篇关于在GCP cloudbuild.yaml中添加“您确定..."对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!