如何使用curl发送环境变量 [英] How to send environment variables using curl
问题描述
我正在尝试使用slack来通知构建完成或GitlabCI上构建失败的时间.我还想做的是附加一个预定义的环境变量$ GITLAB_CI_COMMIT_TITLE,以便与构建通知一起,我还知道哪个提交已完成/失败的构建
I am trying to use slack to notify when a build is complete or if a build fails on GitlabCI. What I also wanna be able to do is append a predefined environment variable $GITLAB_CI_COMMIT_TITLE so along with the build notification I also know which build with what commit has completed/failed
简而言之,
这有效
"curl -X POST -H 'Content-type: application/json' --data '{\"text\":\" Client Staging build complete. \n\"}'
https://hooks.slack.com/services/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"
但这不是
"curl -X POST -H 'Content-type: application/json' --data-binary '{
"'"$CI_COMMIT_TITLE"'" \n\"}'
第二个命令有效,但是它不导出变量的值,我只是在松弛通知中看到'$ CI_COMMIT_TITLE'.
The second command works, but it doesnt export the value of the variable, I just see '$CI_COMMIT_TITLE' in the slack notification.
我做错了什么?任何帮助将不胜感激!谢谢!
What am I doing wrong? Any help will be greatly appreciated! Thank you!
推荐答案
我偶然发现了相同的问题,看来以下解决方案可行:
I stumbled across the same problem and it seems that the following solution works:
curl -X POST -H 'Content-type: application/json'
--data '{"text": " '"$CI_COMMIT_TITLE"' "}'
希望有帮助!
这篇关于如何使用curl发送环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!