How to send environment variables using curl

百般思念 提交于 2020-06-16 03:30:12

问题


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

In short,

This works

"curl -X POST -H 'Content-type: application/json' --data '{\"text\":\" Client Staging build complete. \n\"}'
https://hooks.slack.com/services/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"

But this doesnt

"curl -X POST -H 'Content-type: application/json' --data-binary '{
      "'"$CI_COMMIT_TITLE"'" \n\"}'

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!


回答1:


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"' "}'

Hope it helps!




回答2:


Ghosts anwser is working for me too, but wanted to clarify the space between the " and ' are essential for getting it working.

I tried "'"${CI_COMMIT_TITLE}"'" and kept getting http 500 errors so the space seems to be mandatory.



来源:https://stackoverflow.com/questions/51106956/how-to-send-environment-variables-using-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!