Create Jira Issue on Build Failure through Jenkins

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

Jenkins Jira - DevOpsBuzz

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

Jira Plugin page - DevOpsBuzz

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

Manage Jenkins - DevOpsBuzz

Jira Plugin Jenkins - DevOpsBuzz

Then Go to Configure system and fill your Jira site details

configure Jira in Jenkins - DevOpsBuzz

Once done – Open your Jenkins project

Jenkins Project - DevOpsBuzz

Click on Post build actions

Post Build Action - DevOpsBuzz

Choose “Create Jira issue

create jira issue screenshot - DevOpsBuzz

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

create jira issue project name - DevOpsBuzz

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

create jira issue issue priority - DevOpsBuzz

create jira issue priority selected - DevOpsBuzz

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)

create jira issue type - DevOpsBuzz

create jira issue type selected - DevOpsBuzz

Then select the Action Id

create jira issue action id - DevOpsBuzz

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

Build now - DevOpsBuzz

Build first failure - DevOpsBuzz

console output link - DevOpsBuzz

console output screenshot - DevOpsBuzz

console jira output 1 - DevOpsBuzz

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

Jira Project Screenshot first failure - DevOpsBuzz

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.

Build now - DevOpsBuzz

Build Failure 2 - DevOpsBuzz

console output link - DevOpsBuzz

Build second failure - DevOpsBuzz

console jira output 2 - DevOpsBuzz

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

 

Jira Project Screenshot second failure - DevOpsBuzz

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 ……

25 thoughts on “Create Jira Issue on Build Failure through Jenkins”

    1. 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

      1. 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

        1. Hi Lakshmi,
          Thanks for the details and sorry for delay in reply.
          As shown in the error message Jenkins is not able to fill the custom fields with your configuration.

          The easiest option is to use “Jenkins pipeline script to update Jira fields”, please refer :-https://gist.github.com/t3knoid/6032e574ace2c9e8968bb2b23fc6d280

          Or you can also use JIRA REST APIs which are straight forward and easy to use. please refer :- https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/?_ga=2.61960620.1479629236.1551563524-1579623171.1502183076#editing-an-issue-examples

  1. Hi Ravi varma,
    I am using jenkins 2 version , i have installed jira plugin as you have shown , but i am facing issue during configuration like login failed (Basic auth with password is not allowed on this instance). Please help me out it would be great .
    thanks,
    Rani

    1. Hi Rani,
      Please provide more details for the issue. Are you getting error (Basic auth with password is not allowed on this instance) or Your organisation doesn’t allow you to use username:password to login to Jira/Configure in Jenkins ?

      Are you using Jira cloud ? – then you would need to create the API Token

      If on-premises then :
      Are you able to login to Jira instance using the given credential?
      Are the permission been provided correctly ?
      Please provide the complete stacktrace from Jenkins log

  2. Hi,
    I am trying to create a jira ticket when the build fails in jenkins, however the project key is not validated in JIRA TestResultReporter.
    Jenkins configurations are as below:
    1. JiraTestResultReporter : Provided the URL and gave the API token generated in JIRA for username and password and when validated, I see the messgae JIRA
    2.Jira Software Cloud Integration : Provided the oauth client ID and the secret as the password , test settings – Successfully validated site credentials
    Please suggest how to proceed.

  3. I am facing an issue in creating an issue on JIRA using Jenkins through JIRA: Create issue option from post-build action. Please help

    1. Hi Abdul,

      Can you please provide more details :
      – What issue you are facing ?
      – Is Jira plugin configured correctly ?
      – Are you able to list the issues from Jenkins/APIs ?
      – Are the versions of both Jenkins and Jira are compatible to each other ?
      – Is there any login issue ?
      – Is there any restriction on Jira Project ?
      – Please post exact error from jenkins log

      thank you

  4. Hy
    I wanted to create jira issue with Python script Rest api calling jira and want to run that in jenkins job configuration which create jira issue. I don’t know How to proceed.
    My Python script is reading a file and I want to add rest api Code in that file only and then need to build on jenkins. If you can help with all the steps of it, with an example of Python file reading+rest api Code without creating api token.

  5. Hi Ravi,

    I have been doing the same thing on 2 projects in Jenkins, while build is failed on one project it is creating/updating the issue in Jira while second project build while failing is not creating any issue in Jira. I am surprised same configuration of Jira in Jenkins why it is working for one project and not for other.

  6. Hi Ravi,
    Is there any way to create a Jira ticket automatically based on the errors appearing on jenkinslog file ?

    Thanks,
    Rajasekhar.

  7. Amazing post! is there any configuration to do to fulfill this case scenario: “Build has failed again and now Jenkins should add the comment on existing Jira issue”?

    I understand that when using the “Jira steps” plugin in my declarative pipeline it would create a new JIRA ticket for each failed build

    1. Hi Facundo,

      Thanks for your query.

      Basically, if Jira issue gets created via any Jenkins build failure and same build job gets failed again- then same Jira issue will be updated. There are no additional changes required.

      Hope this helps – Happy learning !!

  8. Edukacja Japonii

    Nice post ! Thanks for, posting on my blog mate! I shall email you some time. I did not know that.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Scroll to Top