6

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
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
walv
  • 2,680
  • 3
  • 31
  • 36

1 Answers1

5

Basic solution is super simple.

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

E.g. -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

walv
  • 2,680
  • 3
  • 31
  • 36
  • 9
    Sorry, may you please check your answer? Are the single quotes outwards or the double quotes? – Sammy Sep 18 '20 at 07:58
  • @Sammy thanks for pointing the error out in my answer. Corrected it, please check. – walv Aug 05 '21 at 14:37
  • 2
    This doesn't address the issue with `echo` – CodyBugstein Aug 18 '21 at 05:27
  • @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. – walv Aug 18 '21 at 21:16