bash - 这是在 cloudbuild.yaml 文件中编写 if..else 语句的正确方法吗?
问题描述
我正在尝试使用 cloudbuild.yaml 部署云功能。如果我不使用任何条件语句,它工作正常。我在执行带有if conditional
语句的 cloudbuild.yaml 文件时遇到错误。什么是正确的写法。下面是我的代码:
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'
我在哪里做错了?
解决方案
从 github 页面https://github.com/GoogleCloudPlatform/cloud-sdk-docker,入口点未设置为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
推荐阅读
- javascript - 以正确格式包含在 html 中时,Javascript 文件不起作用
- reactjs - 如何在滚动视图中呈现有限的内容?
- reactjs - 如何从状态组件访问 ui-router 中的参数(非 url 和 url)?
- mysql - 从 magento 数据库中选择商品的类别名称、产品名称和平均/最低/最高价格
- reactjs - 如何在重新渲染时更新 API 调用?
- windows - 如何在wsl(windows子系统linux)中为shell添加右键单击上下文菜单?
- java - 使用流从元组列表中生成列表元组
- javascript - 语句之间如何使用逗号运算符?
- python - 计算结转效应
- string - 如何将数字与小数点匹配