在 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 ?" 对话框。我怎样才能做到这一点 ?这可以在 jenkins 中完成,但不知道如何在 GCP cloudbuild 中完成。

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 文件:

- 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

在这里,我得到构建成功,但是当条件变为假时,尽管构建成功部署,但我得到以下输出并且构建失败。为什么会这样?

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,你等待结果,没有更多。

但是,您可以自定义步骤。我回答 about the conditional step. Use a substitution variable 运行 你的构建有没有测试。

选择不是交互式的,但是在构建提交时,您可以选择。

-> 我的意思是当你提交构建时,例如手动

gcloud build submit --substitions=_SKIPTEST=true

您选择在提交时跳过测试,而不是在构建期间。

编辑

当您执行 bash -c | 时,假设您在 linux 终端上并按顺序逐行输入命令。对于多行,添加反斜杠 \。这里的 && 是没用的。用它来链接命令,但在这里它没用,因为你是顺序执行命令。

所以这是正确的步骤

- 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