GCP cloudbuild 可选步骤

GCP cloudbuild optional step

在 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)?

使用入口点:'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"

现在我们可以 运行 构建并跳过 step_1:

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