7

I have a very simple pipeline for the tags. When I do the tag, I want to send simple slack webhook. My issue is that environment variable $BITBUCKET_TAG is not rendered neither in echo nor in slack message.

pipelines: tags: '*': - step: script: - echo $BITBUCKET_TAG - curl -X POST "https://hooks.slack.com/services/mysecuritykey" -H "Content-Type:application/json" -H "cache-control:no-cache" -d '{"username":"CoreLib tag","text":"Tag *$BITBUCKET_TAG* has been created"}' 

and I get this in Slack

CoreLib tag [12:50 PM] Tag $BITBUCKET_TAG has been created 

What I want to achieve is to render the $BITBUCKET_TAG value in my echo and in Slack message properly, smth like:

CoreLib tag [12:50 PM] Tag v2019.1.1 has been created 

1 Answer 1

5

Basic solution is super simple.

Instead of $BITBUCKET_TAG should be '"$BITBUCKET_TAG"'.

echo -d '{"username":"CoreLib tag","text":"Tag *'"$BITBUCKET_TAG"'* has been created"}' 

Taken from here: https://superuser.com/questions/835587/how-to-include-environment-variable-in-bash-line-curl

Sign up to request clarification or add additional context in comments.

5 Comments

Sorry, may you please check your answer? Are the single quotes outwards or the double quotes?
@Sammy thanks for pointing the error out in my answer. Corrected it, please check.
This doesn't address the issue with echo
@CodyBugstein can you try $echo '"$BITBUCKET_TAG"' ? I don't work on bitbucket project anymore thus can't validate. But the approach should be the same as in my original answer.
This does not seem to work. I tried echo '"$BITBUCKET_DEPLOYMENT_ENVIRONMENT"' and it just printed "$BITBUCKET_DEPLOYMENT_ENVIRONMENT".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.