作者:mobiledu2502899415 | 来源:互联网 | 2023-01-05 11:54
我正在寻找一种方法将$CI_COMMIT_TAG
我的内部传递.gitlab-ci.yml
给curl
带有json数据的多行命令.但每次我这样做,我得到变量键字符串而不是值.
production:
stage: deploy
script:
- "openssl aes-256-cbc -k $DEPLOY_KEY -in config/deploy_id_rsa_enc_gitlab -d -a -out config/deploy_id_rsa"
- chmod 600 config/deploy_id_rsa
- eval `ssh-agent -s`
- ssh-add config/deploy_id_rsa
- ssh-keyscan -H $HOST_PRODUCTION >> ~/.ssh/known_hosts
- bundle exec cap production deploy tag=$CI_COMMIT_TAG
- "curl --request POST -u $GRAFANA_USR:$GRAFANA_PWD \
--url https://stats.domain.mil/grafana/api/annotations/graphite \
--header 'content-type: application/json' \
--data '{\"what\": \"Deploy: CORE\",\"tags\": [\"production_release\"],\"data\": \"$CI_COMMIT_TAG\"}'"
environment:
name: production
url: https://$HOST_PRODUCTION
only:
- tags
when: manual
我如何通过$CI_COMMIT_TAG
正确的方式?
1> 1resu..:
在单引号内,shell不会扩展.将它们放在双引号内,如下所示:
- "curl --request POST -u $GRAFANA_USR:$GRAFANA_PWD \
--url https://stats.domain.mil/grafana/api/annotations/graphite \
--header 'content-type: application/json' \
--data '{\"what\":\"Deploy: CORE\",\"tags\":[\"production_release\"],\"data\":\"'"$CI_COMMIT_TAG"'\"}'"