Yaml 包括其他`替换中的默认替换`

Yaml 包括其他`替换中的默认替换`,yaml,google-cloud-build,Yaml,Google Cloud Build,从这里 我试图在我的cloudbuild.yaml文件中使用替换,但几乎所有替换都取决于我要部署到的项目的项目ID 我有这样的yaml文件 steps: - name: 'gcr.io/cloud-builders/gcloud' args: ['functions', 'deploy', 'functionName', ...other args... , '--service-account', '${_SERVICE_ACCOUNT}', '--source', '${_SOURCE_

从这里

我试图在我的
cloudbuild.yaml
文件中使用替换,但几乎所有替换都取决于我要部署到的项目的项目ID

我有这样的yaml文件

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['functions', 'deploy', 'functionName', ...other args... , '--service-account', '${_SERVICE_ACCOUNT}', '--source', '${_SOURCE_REPO}']
substitutions:
  _SOURCE_REPO: 'https://source.developers.google.com/projects/$PROJECT_ID/repos/my-repo-id/moveable-aliases/master/paths/functions/src'
  _SERVICE_ACCOUNT: 'blah@${PROJECT_ID}.iam.gserviceaccount.com'
无论我尝试了什么替换(我尝试了两种格式
${u-FOO
${u-FOO}
),最终得到的是
blah@${PROJECT\u-ID}.iam.gserviceaccount.com
,其中仍然有
${PROJECT\u-ID}
文本,而不是实际的项目ID

如果我将文本移动到步骤中,只使用它而不是替换,那么它就工作了。但理想情况下,我希望使用这种方法,因为这些值将被大量使用,所以我希望避免重复

编辑 嗯,我尝试了一些不同的选择,包括@ralemos提到的一些建议,但似乎没有任何效果

如果我使用这种格式

steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['functions', 'deploy', 'functionName', ...other args... , '--service-account', '${SERVICE_ACCOUNT}', '--source', '${SOURCE_REPO}']
options:
  env:
    SOURCE_REPO: 'https://source.developers.google.com/projects/${PROJECT_ID}/repos/my-repo-id/moveable-aliases/master/paths/functions/src'
    SERVICE_ACCOUNT: 'blah@${PROJECT_ID}.iam.gserviceaccount.com
steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['functions', 'deploy', 'functionName', ...other args... , '--service-account', '${SERVICE_ACCOUNT}', '--source', '${SOURCE_REPO}']
options:
  env:
    'SOURCE_REPO=https://source.developers.google.com/projects/${PROJECT_ID}/repos/my-repo-id/moveable-aliases/master/paths/functions/src'
    'SERVICE_ACCOUNT=blah@${PROJECT_ID}.iam.gserviceaccount.com
它抱怨环境线无效

如果我使用这种格式

steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['functions', 'deploy', 'functionName', ...other args... , '--service-account', '${SERVICE_ACCOUNT}', '--source', '${SOURCE_REPO}']
options:
  env:
    SOURCE_REPO: 'https://source.developers.google.com/projects/${PROJECT_ID}/repos/my-repo-id/moveable-aliases/master/paths/functions/src'
    SERVICE_ACCOUNT: 'blah@${PROJECT_ID}.iam.gserviceaccount.com
steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['functions', 'deploy', 'functionName', ...other args... , '--service-account', '${SERVICE_ACCOUNT}', '--source', '${SOURCE_REPO}']
options:
  env:
    'SOURCE_REPO=https://source.developers.google.com/projects/${PROJECT_ID}/repos/my-repo-id/moveable-aliases/master/paths/functions/src'
    'SERVICE_ACCOUNT=blah@${PROJECT_ID}.iam.gserviceaccount.com
它抱怨
SERVICE\u ACCOUNT
SOURCE\u REPO
不是有效的内置替换

如果我使用
$$SOURCE\u REPO
作为语法,它只是将其替换为
$SOURCE\u REPO
,而不是使用替换


现在看来,我所尝试的似乎是不可能的。

您可以使用env变量而不是替换,正如您在本文的答案中所看到的

结果会是这样的:

steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['functions', 'deploy', 'functionName', ...other args... , '--service-account', '${SERVICE_ACCOUNT}', '--source', '${SOURCE_REPO}']
options:
  env:
    SOURCE_REPO: 'https://source.developers.google.com/projects/${PROJECT_ID}/repos/my-repo-id/moveable-aliases/master/paths/functions/src'
    SERVICE_ACCOUNT: 'blah@${PROJECT_ID}.iam.gserviceaccount.com

如果这对您有帮助,请告诉我。

项目名称是默认替代项。我想从传递给我的值中得到它。否则,我每次使用它时都必须进入并编辑它。如果在env变量中使用默认替换会怎么样?这样你就根本不需要替换标签了。我就是这么做的。那也不行。我认为另一个问题中的$$语法不正确。事实上,$$只会在变量本身的值前面加一个$。在这种情况下,请尝试我编辑的答案,它应该有效谢谢,我会试一试。