Cloudbuild.yaml 有环境变量?

Cloudbuild.yaml with enviroment variables?

我有这样的云构建文件

steps:

- name: 'python:3.7'
  entrypoint: 'bash'
  args: 
    - '-c'
    - |
        pip3 install -r requirements.txt
        pytest -rP

#- name: 'gcr.io/cloud-builders/gcloud'
#  args:
#  - functions
#  - deploy
#  - Test_Function
#  - --runtime=python37
#  - --source=https://source.developers.google.com/projects/proj_name/repos/repo_name/moveable-aliases/master/paths/function
#  - --entry-point=main
#  - --trigger-topic=Test_Topic
#  - --region=region

-现在我想做的是我想定义一个变量(Test_name)或环境变量之类的东西,然后将该变量放在我的 yaml 中的不同行中,如下所示。

Test_name: "my_name"
steps:

- name: 'python:3.7'
  entrypoint: 'bash'
  args: 
    - '-c'
    - |
        pip3 install -r requirements.txt
        pytest -rP

#- name: 'gcr.io/cloud-builders/gcloud'
#  args:
#  - functions
#  - deploy
#  - **{Test_name}**_Function
#  - --runtime=python37
#  - --source=https://source.developers.google.com/projects/proj_name/repos/repo_name/moveable-aliases/master/paths/function
#  - --entry-point=main
#  - --trigger-topic=**{Test_name}**_Topic
#  - --region=region

我该怎么做?

您可以使用 Cloud Build 的替换来实现这一点,如官方 docs 中所述。

按照上述文档中提供的示例,您的 cloudbuild.yaml 将如下所示:

Test_name: "my_name"
steps:

- name: 'python:3.7'
  entrypoint: 'bash'
  args: 
    - '-c'
    - |
        pip3 install -r requirements.txt
        pytest -rP

#- name: 'gcr.io/cloud-builders/gcloud'
#  args:
#  - functions
#  - deploy
#  - ${_TEST_NAME}_Function
#  - --runtime=python37
#  - --source=https://source.developers.google.com/projects/proj_name/repos/repo_name/moveable-aliases/master/paths/function
#  - --entry-point=main
#  - --trigger-topic=${_TEST_NAME}_Topic
#  - --region=region

substitutions:
    TEST_NAME: TEST # default value