Dirk
Dirk

Reputation: 1194

How to create a JIRA new Issue using the Jenkins Jira Steps Plugin

I would like to create a new Jira Issue using the Jenkins Jira Steps Plugin.

Here is my Demo Pipeline:

node {
  stage('JIRA') {
    def testIssue = [fields: [ project: [id: '1'],
                                 summary: 'New JIRA Created from Jenkins.',
                                 description: 'New JIRA Created from Jenkins.',
                                 issuetype: [id: '11']]]

      response = jiraNewIssue issue: testIssue, site: 'JIRA T'

      echo response.successful.toString()
      echo response.data.toString()
    }
}

After running the Pipeline I get:

[Pipeline] node
Running on master in /home/tomcat/.jenkins/workspace/Jira-RFC-Demo-Pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (JIRA)
[Pipeline] jiraNewIssue
JIRA: Site - JIRA T - Creating new issue: IssueInput(update=null, fields={project={id=1}, summary=New JIRA Created from Jenkins., description=New JIRA Created from Jenkins., issuetype={id=11}})
Error Code: 400
Error Message: {"errorMessages":[],"errors":{"project":"project is required"}}
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: {"errorMessages":[],"errors":{"project":"project is required"}}
Finished: FAILURE

So it looks like the plugin isn't able to read the project from the testIssue. Nevertheless this should be the way to create an issue as documented in the link above.

Any Ideas?

Upvotes: 0

Views: 6895

Answers (1)

Dirk
Dirk

Reputation: 1194

I think the error message is misleading. The following did the trick:

node {
  stage('JIRA') {
    def testIssue = [fields: [ project: [key: 'RFC'],
                                 summary: 'New JIRA Created from Jenkins.',
                                 description: 'New JIRA Created from Jenkins.',
                                 issuetype: [id: '10500']]]

      response = jiraNewIssue issue: testIssue, site: 'JIRA T'

      echo response.successful.toString()
      echo response.data.toString()
    }
}

The difference was using the key instead the project-id. So maybe the id was simply not existing or invalid.

Anyway, I think using the key is more expressive.

Upvotes: 2

Related Questions