我需要一些有关云构建的帮助--substitutions
。
这是文档:https ://cloud.google.com/cloud-build/docs/build-config#substitutions
这是说的:
cloudbuild.yaml
substitutions:
_SUB_VALUE: world
options:
substitution_option: 'ALLOW_LOOSE'
以下代码段使用替换来打印“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