69618

How to send environment variables using curl

<h3>Question</h3>

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!


<h3>Answer1:</h3>

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!


<h3>Answer2:</h3>

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

Recommend

  • android- ble device status shows connected for some seconds even after turning off the device
  • print content of which exceeds one page
  • Identification of clients
  • The closing braces of my C# code are not recognized in a Razor partial view
  • get the duplicates values from Arraylist and then get those items in another Arraylist
  • When exactly does Mongoid actually make a query to MongoDb
  • Determine Active Panel
  • Force outer SELECT to fail if the inner SELECT contains an invalid identifier
  • How exactly do you use json_decode to pass a javascript array to php?
  • Override all shipping costs for a specific shipping class in Woocommerce
  • if you have a DLL creating a bitmap in memory, how to return it to the browser?
  • Use awk to convert GPS Position to Latitude & Longitude
  • Querying Elasticsearch Address Based Index
  • SpringBoot don't replacen System variable {user.home} in Spring Tool Suite Version: 3.8.4.RELEA
  • How can I do case insensitive string search with Linq and SQL Server?
  • Php artisan optimize is failing on production server
  • UIScrollView does not restore properly
  • Update all WooCommerce product prices to 2 decimals in database
  • GTK3 + OpenGL for windows: multiple GtkGLArea (ie. OpenGL contexts)
  • Why do you need 2 Javascript files for cross-platform Cordova plugin?
  • How to define a custom accuracy in Keras to ignore samples with a particular gold label?
  • C# code can't “see” the methods in my C++ dll
  • All Event listing on specified date in Google Calender api (V3) in java?
  • Annotate objects in a queryset with next and previous object ids
  • How to run chrome.tabs.insertCSS from the background page on each page?
  • I am consuming a WCF service that requires headers from a .NET 2 website. How can I programmatically
  • Unable to create Access token grant type in wso2 API manager store to test API
  • how to run ejabberd with Erlang on Heroku?
  • How to use Streams api peek() function and make it work?
  • How to specify generic type when the type is only known at runtime?
  • How to decleare char *const argv[] in swift [duplicate]
  • Did not understand process of initialize in swift programming
  • What is the best way to cache and reuse immutable singleton objects in Java?
  • How to encrypt Connectionstring written in web.config from codebehind?
  • How to get rgb from transparent pixel in js
  • Grails - How to implement a foreign key relationship not using an id column?
  • How to call different template for different category archive page in woocommerce
  • WPF custom control and direct content support
  • Time Complexity of Fibonacci Algorithm [duplicate]