GCP cloudbuild可选步骤

时间:2019-08-19 20:29:01

标签: google-cloud-platform google-cloud-build

在cloudbuild.yaml上具有此配置(文件上还有其他类似的片段):

- name: 'gcr.io/cloud-builders/gcloud'
  id: 'step_1'
  args: ['builds',
         'submit',
         '--config=path_to_sub_app_1/app_1_build.yaml',
         '--substitutions=VAR_1=${ENV_VAR_1}']
  waitFor: ['Docker push']

- name: 'gcr.io/cloud-builders/gcloud'
  id: 'step_2'
  args: ['builds',
         'submit',
         '--config=path_to_sub_app_2/app_2_build.yaml',
         '--substitutions=VAR_1=${ENV_VAR_1}']
  waitFor: ['Docker push']

是否可以跳过step_1并继续正常执行(step_2)?

1 个答案:

答案 0 :(得分:2)

使用入口点:'bash'

- name: 'gcr.io/cloud-builders/gcloud'
  id: 'step_1'
  entrypoint: 'bash'
  args:
    - '-c'
    - |
      if [ "$_SKIP_STEP" != "true" ]
      then
        gcloud builds submit --config=path_to_sub_app_1/app_1_build.yaml --substitutions=VAR_1=${ENV_VAR_1}
      fi
  waitFor: ['Docker push']

定义此变量: _SKIP_STEP =“ false”

现在我们可以运行构建并跳过步骤_1:

gcloud builds submit --config=cloudbuild.yaml --substitutions=_SKIP_STEP=true