Cloudbuild.yaml与环境变量?

时间:2020-06-03 11:23:32

标签: google-cloud-platform yaml google-cloud-build

我有类似这样的云构建文件

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

我该怎么做?

1 个答案:

答案 0 :(得分:1)

如官方docs所述,您可以利用Cloud Build的替代品来实现。

按照上述文档中提供的示例,您的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