I'm searching for a way to pass the $CI_COMMIT_TAG
within my .gitlab-ci.yml
to a multiline curl
command with json data. But every time I do so I get the variable-key-string istead of the value.
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
How do I pass the $CI_COMMIT_TAG
the correct way?
Go to Settings > CI/CD. Click Expand in the Variables section. Select the State and Masked values you want for your variable.
These are scripts that you choose to be run before the job is executed or after the job is executed. These can also be defined at the top level of the YAML file (where jobs are defined) and they'll apply to all jobs in the . gitlab-ci. yml file.
CI_COMMIT_TAG - The commit tag name. Present only when building tags. Therefore in the variables section CI_COMMIT_TAG is not defined, hence equals to "". So if you want to use CI_COMMIT_TAG use in job where tags are defined.
Inside single-quotes, the shell expands nothing. Place them inside double-quotes like this:
- "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"'\"}'"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With