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?

1 Answer 1

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"'\"}'"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.