【发布时间】:2021-04-23 01:58:27
【问题描述】:
我需要一些有关云构建的帮助--substitutions。
这是文档:https://cloud.google.com/cloud-build/docs/build-config#substitutions
这是说的:
cloudbuild.yaml
substitutions:
_SUB_VALUE: world
options:
substitution_option: 'ALLOW_LOOSE'
下面的 sn-p 使用替换来打印“hello world”。
ALLOW_LOOSE替换选项已设置,这意味着如果缺少替换变量或缺少替换,构建将不会返回错误。
我的情况:我没有使用ALLOW_LOOSE 选项。我需要我的替代品。我不希望应用任何默认值。如果我忘记传递任何我需要的替换,我需要它立即失败。
这是我的cloudbuild.yaml 文件:
cloudbuild.yaml
substitutions:
_SERVER_ENV: required
_TAG_NAME: required
_MIN_INSTANCES: required
我将它们的默认值初始化为required,特别是因为如果我忘记将它们中的任何一个传递给gcloud builds submit 调用,我预计构建调用会失败。
如果我调用gcloud builds submit 并且不传递任何定义的替换,我预计它会失败。但它并没有失败,并且构建正常完成,没有该值。
文档中有这样的观察:
注意:如果您的构建由触发器调用,则默认设置 ALLOW_LOOSE 选项。在这种情况下,如果缺少替换变量或缺少替换变量,您的构建将不会返回错误替代。您不能为触发器调用的构建覆盖 ALLOW_LOOSE 选项。
但如果我手动调用gcloud builds submit,这意味着我的构建没有被任何触发器调用,对吧?因此不应启用ALLOW_LOOSE 选项。
这是我完整的cloudbuild.yaml:
cloudbuild.yaml
steps:
- name: "gcr.io/cloud-builders/docker"
args:
- "build"
- "--build-arg"
- "SERVER_ENV=$_SERVER_ENV"
- "--tag"
- "gcr.io/$PROJECT_ID/server:$_TAG_NAME"
- "."
timeout: 180s
- name: "gcr.io/cloud-builders/docker"
args:
- "push"
- "gcr.io/$PROJECT_ID/server:$_TAG_NAME"
timeout: 180s
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
entrypoint: gcloud
args:
- "beta"
- "run"
- "deploy"
- "server"
- "--image=gcr.io/$PROJECT_ID/server:$_TAG_NAME"
- "--platform=managed"
- "--region=us-central1"
- "--min-instances=$_MIN_INSTANCES"
- "--max-instances=3"
- "--allow-unauthenticated"
timeout: 180s
images:
- "gcr.io/$PROJECT_ID/server:$_TAG_NAME"
substitutions:
_SERVER_ENV: required
_TAG_NAME: required
_MIN_INSTANCES: required
【问题讨论】:
标签: google-cloud-build cloudbuild.yaml