Maria Bohorquez
Maria Bohorquez

Reputation: 89

How to add pass a env variable as part of a json in Github Actions?

I have the following steps as part of a Github Workflow:

run: |
    MESSAGE="${{ env.MESSAGE }}" && echo $MESSAGE \ &&
    curl -X POST -H 'Content-type: application/json' --data '{"text":$MESSAGE}' https://hooks.slack.com/services/<some_ids>

The echo works and outputs the correct message, but replacing the message in the json fails. What is the correct syntax?

I already tried escaping the quotes (it's not valid syntax):

--data '{"text":\"$MESSAGE\"}' 

Upvotes: 1

Views: 4013

Answers (1)

Cyril Jouve
Cyril Jouve

Reputation: 1050

you are putting your variable between simple quotes : --data '{"text":$MESSAGE}' which prevents interpolation of $MESSAGE.

you have to put $MESSAGE between double quotes: --data "{\"text\": $MESSAGE}"

Upvotes: 4

Related Questions