我正在寻找一种方法来将$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
正确的方法?
在单引号内,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"'\"}'"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句