How to make a curl request with json in jenkins pipeline groovy script

后端 未结 2 2040
独厮守ぢ
独厮守ぢ 2021-02-14 01:03

I am trying to make a New Relic deployment API call as a Jenkins build step using the Groovy pipeline. I\'m having trouble because of the use of both single and double quotes wi

相关标签:
2条回答
  • 2021-02-14 01:03

    I've had a similar issue when I created a job that creates a new repository in Github using Github's API.

    I've fixed it by replacing the single ticks with quotes and escaped the quotes inside the json object like so:

    curl -H "Authorization: token ${ACCESSTOKEN}" --data "{\"name\":\"${REPONAME}\"}" https://api.github.com/orgs/Company/repos
    
    0 讨论(0)
  • 2021-02-14 01:28

    The 'json' variable contains a string that has an extra trailing single quote (').

    When this is used in -d '${json}'" I suspect it will result in an extra (') in the data block. The data block will require the JSON be enclosed in single quotes so make certain those are included.

    Not being a Groovy person (pun intended) you may have to play with escaping characters it ensure that the correct string is passed to the cURL command.

    0 讨论(0)
提交回复
热议问题