如何在 Google Cloud build with Python 中创建具有多个替换变量的触发器
How to create trigger with multiple substitutions variable in Google Cloud build with Python
我正在编写 Python 代码来创建 Google 云触发器,我无法添加替换变量。
目前我有以下代码
from google.cloud.devtools import cloudbuild_v1
client = cloudbuild_v1.CloudBuildClient()
build_trigger_template = cloudbuild_v1.types.BuildTrigger()
build_trigger_template.description = 'test to create trigger'
build_trigger_template.name = 'github-cloudbuild-trigger1'
build_trigger_template.github.name = 'github-cloudbuild'
build_trigger_template.github.pull_request.branch = 'master'
build_trigger_template.filename = 'cloudbuild.yaml'
response = client.create_build_trigger('dev',
build_trigger_template)
我想添加两个替换变量 _ENV 和 _PROJECT,我尝试了下面提到的方法但没有用。
build_trigger_template.substitutions = {'_ENV': 'test',
'_PROJECT': 'pro-test'}
错误:AttributeError:不允许分配给协议消息对象中的重复字段 "substitutions"。
谢谢,
拉古纳特。
这是分配 protobuf 对象的问题。
如果您使用 dir(build_trigger_template.substitutions)
查看对象
您会找到一个 .update
接受字典的方法。
所以试试下面的方法,它应该 return None
但你的结构会更新。
build_trigger_template.substitutions.update({'_ENV': 'test',
'_PROJECT': 'pro-test'})
我正在编写 Python 代码来创建 Google 云触发器,我无法添加替换变量。
目前我有以下代码
from google.cloud.devtools import cloudbuild_v1
client = cloudbuild_v1.CloudBuildClient()
build_trigger_template = cloudbuild_v1.types.BuildTrigger()
build_trigger_template.description = 'test to create trigger'
build_trigger_template.name = 'github-cloudbuild-trigger1'
build_trigger_template.github.name = 'github-cloudbuild'
build_trigger_template.github.pull_request.branch = 'master'
build_trigger_template.filename = 'cloudbuild.yaml'
response = client.create_build_trigger('dev',
build_trigger_template)
我想添加两个替换变量 _ENV 和 _PROJECT,我尝试了下面提到的方法但没有用。
build_trigger_template.substitutions = {'_ENV': 'test',
'_PROJECT': 'pro-test'}
错误:AttributeError:不允许分配给协议消息对象中的重复字段 "substitutions"。
谢谢,
拉古纳特。
这是分配 protobuf 对象的问题。
如果您使用 dir(build_trigger_template.substitutions)
您会找到一个 .update
接受字典的方法。
所以试试下面的方法,它应该 return None
但你的结构会更新。
build_trigger_template.substitutions.update({'_ENV': 'test',
'_PROJECT': 'pro-test'})