Create Jira Issue on Build Failure through Jenkins

Topic Tools

Now a days, its quite necessary and really very useful to integrate Jira with Jenkins

Jira can be used as Issue Tracking, Project management,etc for your project and brings Agility with its Scrum board and processes.

The most common use case is to update Jira ticket as and when there is an update on Jenkins build job.

How to achieve that ?

Lets discuss this today and see how can we update Jira issue whenever there is a failure on your respective Jenkins build job.

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.

To begin with the process you should first :-

Install Jira plugin in Jenkins

Check out the Jira Plugins in Jenkins wiki

And then download and install through Manage Jenkins —> Manage Plugins

Then Go to Configure system and fill your Jira site details

Once done – Open your Jenkins project

Click on Post build actions

Choose “Create Jira issue

And fill the details accordingly.

Since you have already configured your Jira project in Configure system, the details will be fetch and auto populated from your Jira instance to Jenkins Project.

Provide the Jira Project Key and Description the the test

Then choose Issue priority from the dropdown (It will fetch the Priority field from provide Jira project)

Select Issue Type (You need to provide the issue type which you want to be created in Jira for that particular project whenever there is any update through Jenkins build)

Then select the Action Id

Save it

Now, whenever the build gets failed, Jenkins will create an issue in Jira project.

Lets try some cases :

Case# 1 – Build is failed. Now Jenkins should create an issue inside the given Jira Project

Lets check our Jira, whether Jenkins has created the issue or not ?

Yes, it has created a Jira issue 🙂

Lets proceed and test another case

Case# 2 – Build has failed again and now Jenkins should add the comment on existing jira issue.

Lets check our Jira instance again, whether Jenkins has update the issue or not ?

 

Hurrayyy – Jenkins has updated the same issue as expected.

Folks, today we have seen how to create a Jira issue through Jenkins by following very simple steps.

Hope you enjoyed reading this article. Will be back with new Jenkins error soon.

Till then, stay tuned ……

5 comments… add one
  • Laxmi Link Reply

    Jira issue is not getting created

    • Hi Laxmi,
      Please can you share some details:
      – What issue you are facing ?
      – Did you follow the complete steps as per the above post ?
      Thanks in advance

      • Laxmi Link Reply

        I am getting null pointer exception as Other fields like version, application type are mandatory fields in my app to create jira. but on job configuration i don’t know where to configure that.

        : JIRA REST createIssue error: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={customfield_15607=ALM Project Name is required., customfield_15407=Detected in Cycle is required., customfield_11602=Application is required., customfield_11604=Severity is required., versions=Affects Version/s is required., customfield_15608=Detected in Env is required., fixVersions=Fix Version/s is required., customfield_15405=Test Phase is required., customfield_15601=Team Category is required.}, errorMessages=[]}]}

        ERROR: Build step failed with exception
        java.lang.NullPointerException
        at hudson.plugins.jira.JiraSession.createIssue(JiraSession.java:412)
        at hudson.plugins.jira.JiraCreateIssueNotifier.createJiraIssue(JiraCreateIssueNotifier.java:202)
        at hudson.plugins.jira.JiraCreateIssueNotifier.currentBuildResultFailure(JiraCreateIssueNotifier.java:357)
        at hudson.plugins.jira.JiraCreateIssueNotifier.perform(JiraCreateIssueNotifier.java:157)
        at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
        at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
        at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
        at hudson.model.Build$BuildExecution.post2(Build.java:186)
        at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
        at hudson.model.Run.execute(Run.java:1835)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:97)
        at hudson.model.Executor.run(Executor.java:429)
        Build step ‘JIRA: Create issue’ marked build as failure
        Finished: FAILURE

  • Renate Link Reply

    Hi there! Such a good article, thanks!

Leave a Comment