Bash 这是在cloudbuild.yaml文件中写入if..else语句的正确方法吗?
我正在尝试使用cloudbuild.yaml部署一个云函数。如果我不使用任何条件语句,它就可以正常工作。使用if条件语句执行cloudbuild.yaml文件时,我遇到了一个错误。正确的写作方法是什么。下面是我的代码:Bash 这是在cloudbuild.yaml文件中写入if..else语句的正确方法吗?,bash,google-cloud-platform,google-cloud-functions,yaml,google-cloud-build,Bash,Google Cloud Platform,Google Cloud Functions,Yaml,Google Cloud Build,我正在尝试使用cloudbuild.yaml部署一个云函数。如果我不使用任何条件语句,它就可以正常工作。使用if条件语句执行cloudbuild.yaml文件时,我遇到了一个错误。正确的写作方法是什么。下面是我的代码: steps: - name: 'gcr.io/cloud-builders/gcloud' id: deploy args: - '-c' - 'if [ $BRANCH_NAME != "xoxoxoxox" ] then [
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',
'--service-account=xoxoxoxox@appspot.gserviceaccount.com'
]
fi'
dir: 'API/groups'
我哪里做错了?我不确定你能做到这一点 在我的例子中,我使用Cloud build触发器中的分支选择器来选择要从模式中构建的分支或标记。在github页面中,入口点未设置为gcloud。所以不能像那样指定参数 指定目录的最佳实践是从/workspace开始 此外,编写步骤的正确方法应该是
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
--service-account=xoxoxoxox@appspot.gserviceaccount.com
fi
这回答了你的问题吗?它部分地回答了这个问题。我尝试了你的解决方案,但没能解决问题。可能是这样,我不会遵循您的解决方案。此处不需要&&命令,因为该命令是按顺序执行的,但没有链接。这是代码。谢谢你抽出时间如何检查云计划程序是否已经存在?这样我的云构建就不会说错误:gcloud.scheduler.jobs.create.http已经存在:?