'How to create a new JIRA issue when jenkins job failed

I can able to create the new issue in Jira using this ("JIRA Pipeline steps") plugin in the pipeline script.

node {
  stage('JIRA') {
    def server = "cloudjira"

    def testIssue = [fields: [ project: [id: '10000'],
                                 summary: 'Issue created from Jenkins.',
                                 description: 'Created from Jenkins.',
                                 issuetype: [id: '10001']]]

      response = jiraNewIssue issue: testIssue, site: 'server'

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

But I need to create a new issue based on the Jenkins job status.

Requirements:

  1. If the current job failed, check if the issue was already created. If yes, adds a comment, if not, create a new JIRA issue.

  2. If the current job passed, check if the issue from (point 1) is Closed or Done. If not, adds a comment.

  3. And if the issue is not fixed and the job has failed again- It will add the comment on the existing Jira issue.

  • Jenkins running in my local environment. Jenkins version: 2.319.3
  • Jira running on the cloud instance.

Is there any other plugin to achieve the above requirements or any different approach?

I am Requesting your help to resolve this issue !!!



Solution 1:[1]

Using "Post-build Actions" of Jenkins. An easy step-by-step guide to follow is here.

For summary:

  • Install Jira plugin in Jenkins: download and install through Manage Jenkins -> Manage Plugins
  • Go to Configure system and fill your Jira site details
  • Open your Jenkins project
  • Click on Post build actions
  • Choose “Create Jira issue”
  • Fill the details accordingly.
  • Then select the Action Id

The page also said that it was tested for cases:

You can create a JIRA issue in the project with the given Jira project key.

If current build failed, checks if issue was already created. If yes, adds a comment, if not, creates a new JIRA issue.

If current build passed, checks if issue from p.1 is Closed or Done. If not, adds a comment.

And if the issue is not fixed and build has failed again- It will add the comment on existing jira issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nnhthuan