Bitbucket 管道:echo 环境变量

wal*_*alv 7 bash bitbucket environment-variables slack-api bitbucket-pipelines

我有一个非常简单的标签管道。当我做标签时,我想发送简单的 slack webhook。我的问题是环境变量$BITBUCKET_TAG既没有在松弛消息中呈现echo,也没有在松弛消息中呈现。

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"}'
Run Code Online (Sandbox Code Playgroud)

我在 Slack 中得到了这个

CoreLib tag [12:50 PM]

Tag $BITBUCKET_TAG has been created
Run Code Online (Sandbox Code Playgroud)

我想要实现的是正确呈现$BITBUCKET_TAGecho和 Slack 消息中的值,例如:

CoreLib tag [12:50 PM]

Tag v2019.1.1 has been created
Run Code Online (Sandbox Code Playgroud)

wal*_*alv 7

基本解决方案非常简单。

而不是$BITBUCKET_TAG应该是'"$BITBUCKET_TAG"'

echo -d '{"username":"CoreLib tag","text":"Tag *'"$BITBUCKET_TAG"'* has been created"}'
Run Code Online (Sandbox Code Playgroud)

摘自这里: https: //superuser.com/questions/835587/how-to-include-environment-variable-in-bash-line-curl

  • 抱歉,您可以检查一下您的答案吗?单引号朝外还是双引号朝外? (9认同)
  • 这并没有解决“echo”的问题 (2认同)