Curl using Environment variables in GitLab-ci.yml

1.6k views Asked by At

I'm trying to send a slack notification using the .gitlab-ci.yml and I need to pass the Commit's message in the message like this: "The version ${CI_COMMIT_TAG} Version is available!"

But i'm still not able to get the environment variable desired when receiving the notification on my channel and passing it like this in the file:

script: 
    - "curl -X POST -H 'Content-type: application/json' --data '{\"text\":\"The version ${CI_COMMIT_TAG} version is available!\"} ' https://hooks.slack.com/services/....../......"

Do you have any clues ? I'm not used to Curl and Yaml

Thanks and Have a good day!

1

There are 1 answers

0
sytech On

--data '...'

Variable expansion in bash does not work within single quotes. Use double quotes instead.

Alternatively, use a data file to avoid formatting JSON inline:

curl -d "@data.json" ...