简体   繁体   English

如何在 Github Actions 中添加传递 env 变量作为 json 的一部分?

[英]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:作为 Github 工作流的一部分,我有以下步骤:

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. echo 工作并输出正确的消息,但替换 json 中的消息失败。 What is the correct syntax?什么是正确的语法?

I already tried escaping the quotes (it's not valid syntax):我已经尝试转义引号(它不是有效的语法):

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

you are putting your variable between simple quotes : --data '{"text":$MESSAGE}' which prevents interpolation of $MESSAGE .您将变量放在简单的引号之间: --data '{"text":$MESSAGE}'这可以防止$MESSAGE插值。

you have to put $MESSAGE between double quotes: --data "{\\"text\\": $MESSAGE}"你必须把$MESSAGE放在双引号之间: --data "{\\"text\\": $MESSAGE}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM