Noa*_*ltz 2 yaml bitbucket syntax-error cloudflare
当我部署到生产环境时,我尝试curl向 bitbucket 上的 CI/CD YAML 添加命令。该curl命令向 CloudFlare API 发送 POST 请求以清除缓存。该命令包含-H变量作为必要的 HTTP 标头。这导致 bitbucket 上出现缩进错误,因此我无法提交更改,而且我不确定原因。我不熟悉 YAML 语法以及如何解决此问题。
bitbucket-pipelines.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}'"
Run Code Online (Sandbox Code Playgroud)
您需要转义命令中的双引号。此外,-H连续行缩进不够远 \xe2\x80\x93 它们必须缩进超过标量开始的行上的列表项指示符。
更好的方法是使用折叠块标量:
\n - >-\n curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE\\purge_cache"\n -H "X-Auth-Email: $CLOUDFLARE_AUTH_EMAIL"\n -H "X-Auth-Key: $CLOUDFLARE_AUTH_KEY"\n -H "Content-Type: application/json" --data '{"purge_everything":true}'\nRun Code Online (Sandbox Code Playgroud)\n折叠块标量将换行符折叠成空格并且不处理任何特殊字符,因此您不需要转义任何内容(事实上,块标量中没有转义序列)。
\n