Sunday, July 24, 2022

[SOLVED] I want to create an issue in jira using jenkins pipeline but not with any plugin, is there a way to do so?

Issue

here is how the stage in my pipeline looks like

 stage('jira'){
             steps{
           bat 'curl --request POST  --url 'https://ID.atlassian.net/rest/api/2/issue'  --user '[email protected]:<token>'  --header 'Accept: application/json'  --header 'Content-Type: application/json'  --data '{"fields": {"project":{"key": "FIT"},"summary": "created for j","description": "Created for j","issuetype": {"name": "Task"}}}''
                 }
        }

and here is what the error looks like

Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 64: expecting '}', found ':'

if anyone knows any other way to achieve this in pipeline then please tell...


Solution

Solution

You need to use escape characters for nested single quotes.

You can use the Jenkins Syntax generator to produce this. The syntax generator is located at https://< base-url >.com/pipeline-syntax/

stage('jira') {
    steps {
        bat 'curl --request POST  --url \'https://ID.atlassian.net/rest/api/2/issue\'  --user \'[email protected]:<token>\'  --header \'Accept: application/json\'  --header \'Content-Type: application/json\'  --data \'{"fields": {"project":{"key": "FIT"},"summary": "created for j","description": "Created for j","issuetype": {"name": "Task"}}}'
    }
}


Answered By - Chris Maggiulli
Answer Checked By - Senaida (WPSolving Volunteer)