Search code examples
jenkinscurljirajenkins-declarative-pipeline

Running curl command from Jenkins declarative pipeline


I am trying to execute the curl post command from Jenkins declarative pipeline, however, it is throwing a syntax error -- Expecting '}' found ':'

The pipeline script is below:

pipeline {

   agent { label ' Linux01'}

   stages {

      stage('Hello') {

         steps {

            sh 'curl -u username:password -X POST -d '{"body":"Jenkinspipleinecomment"}' -H "Content-Type:application/json" http://localhost:8080/rest/api/2/issue/someissue/comment'
    
         }
      }
   }
}

Kindly help.


Solution

  • Try this out

    pipeline {
    
    agent { label ' Linux01'}
    
    stages {
    
      stage('Hello') {
    
         steps {
    
            sh """curl -u username:password -X POST -d '{"body":"Jenkinspipleinecomment"}' -H "Content-Type:application/json" http://localhost:8080/rest/api/2/issue/someissue/comment"""
    
         }
      }
    } }