6

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?

Thomas Schwärzl
  • 9,518
  • 6
  • 43
  • 69

1 Answers1

16

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"'\"}'"
1resu
  • 514
  • 4
  • 11