yaml - curl 命令导致 bitbucket CI/CD 管道 YAML 中的缩进错误
问题描述
当我部署到生产环境时,我试图在 bitbucket 上向我的 CI/CD YAML 添加一个curl
命令。该curl
命令向 CloudFlare API 发送 POST 请求以清除缓存。该命令包括-H
必要的 HTTP 标头变量。这会导致 bitbucket 出现缩进错误,因此我无法提交更改,我不知道为什么。我不熟悉 YAML 语法以及我应该如何解决这个问题。
位桶管道.YAML
image: python:3.7.4
clone:
depth: full
pipelines:
default:
- step:
caches:
- pip
script:
- echo "nothing"
branches:
prod:
- step:
name: Deploy to Staging
deployment: staging
script: #staging script
- git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_STAGING_APP_NAME.git HEAD:master --force
- step:
name: Deploy to Production
deployment: production
trigger: manual
script: #production script
- git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD:master --force
- "curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE\purge_cache" -H "X-Auth-Email: $CLOUDFLARE_AUTH_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_AUTH_KEY" \
-H "Content-Type: application/json" --data '{"purge_everything":true}'"
解决方案
您需要转义命令中的双引号。此外,-H
续行的缩进不够远——它们必须比标量开始行上的列表项指示符缩进更多。
更好的方法是使用折叠块标量:
- >-
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE\purge_cache"
-H "X-Auth-Email: $CLOUDFLARE_AUTH_EMAIL"
-H "X-Auth-Key: $CLOUDFLARE_AUTH_KEY"
-H "Content-Type: application/json" --data '{"purge_everything":true}'
折叠块标量将换行符折叠成空格并且不处理任何特殊字符,因此您不需要转义任何内容(实际上,块标量中没有转义序列)。
推荐阅读
- java - 如何更改 javafx 图表的轴颜色?
- linux - Systemd 在启动时延迟日历事件的启动时间或等待其他服务
- c# - button_onclick() 在 .aspx 页面本身中生成
- html - 如何阻止对 API 生成的 URL 的抓取和索引?
- c# - 如何在外键列上更新和插入值?
- python - 使用 exec(open()) 将参数传递给 python 脚本
- python - 当我将local的值设置为大于1时,为什么pyspark会出现错误
- python-3.x - 为什么 asyncio call_later() 不能在 python 中工作?
- android - 将 Play Services 升级到 15.0.0 后出现 MergerException: Unable to merge dex while running
- oracle - 无法从 12c 中的 V$RMAN_BACKUP_JOB_DETAILS 取回任何行