问题描述
我正在尝试使用cloudbuild.yaml部署云功能.如果我不使用任何条件语句,它就可以正常工作.使用if conditional
语句执行cloudbuild.yaml文件时遇到错误.编写它的正确方法是什么?下面是我的代码:
I am trying to deploy a cloud function using cloudbuild.yaml. It works fine if I don't use any conditional statement. I am facing an error when I execute my cloudbuild.yaml file with if conditional
statement. What is the correct way to write it. Below is my code:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
id: deploy
args:
- '-c'
- 'if [ $BRANCH_NAME != "xoxoxoxox" ]
then
[
'functions', 'deploy', 'groups',
'--region=us-central1',
'--source=.',
'--trigger-http',
'--runtime=nodejs8',
'--entry-point=App',
'--allow-unauthenticated',
'[email protected]'
]
fi'
dir: 'API/groups'
我在哪里做错了?
推荐答案
在github页面上, https://github.com/GoogleCloudPlatform/cloud-sdk-docker ,入口点未设置为gcloud
.因此,您不能指定类似的参数.
From the github page, https://github.com/GoogleCloudPlatform/cloud-sdk-docker, the entrypoint is not set to gcloud
. So you cannot specify the arguments like that.
指定目录的好习惯是从/workspace
Good practice for specifying directory is to start with /workspace
写步骤的正确方法应该是
Also the right way to write the step should be
steps:
- name: 'gcr.io/cloud-builders/gcloud'
id: deploy
dir: '/workspace/API/groups'
entrypoint: bash
args:
- '-c'
- |
if [ $BRANCH_NAME != "xoxoxoxox" ]
then
gcloud functions deploy groups
--region=us-central1
--source=.
--trigger-http
--runtime=nodejs8
--entry-point=App
--allow-unauthenticated
[email protected]
fi
这篇关于这是在cloudbuild.yaml文件中编写if..else语句的正确方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!