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.
|
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 ……
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
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
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
Hi there! Such a good article, thanks!
Hi Ravi , How can I update status of an already created issue once my jenkins job is triggered .
Hi Rishuvee,
Thanks for your query.
Yes, it is possible either through Jenkins Plugins ( you can use https://wiki.jenkins.io/display/JENKINS/Jira+Issue+Updater+Plugin and refer https://github.com/jenkinsci/jira-issue-updater-plugin for more details) or through Jira REST API calls (please refer https://developer.atlassian.com/cloud/jira/platform/rest/v3/?).
Hope this helps
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
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
can you explain the same using descriptive jenkins pipeline
I’ll write a post soon to cover the jira issue creation/ update comment through Jenkins pipeline.
For time being, please look into this plugin and give a try : https://jenkinsci.github.io/jira-steps-plugin/index.html
I had used Jira Pipeline Steps plugin to create new Jira Issue
Hope it helps !!
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.
Hi,
Please see if your issue relates to this article : https://community.atlassian.com/t5/Jira-Software-questions/My-project-key-is-invalid-on-jenkins-even-though-the-project-key/qaq-p/1335493
Thanks
I am facing an issue in creating an issue on JIRA using Jenkins through JIRA: Create issue option from post-build action. Please help
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
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.
Hi Swapnil,
Please try with Create-Jira-issue-via-rest-api-python and/or create a task on Jira
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.
Hi Amit,
Please could you provide more details, what error are you getting in build log and in jenkins log, etc
Hi Ravi,
Is there any way to create a Jira ticket automatically based on the errors appearing on jenkinslog file ?
Thanks,
Rajasekhar.
Hi Rajasekhar,
Thanks for your message.
If you are not willing to integrate Jira with Jenkins via Jira plugin or Jira Pipeline Steps, etc – then you can simply create a script in any of your favourite language – to read the jenkins log and create a Jira ticket directly on Jira dashboard by utlizing Jira APIs
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
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 !!
Nice post ! Thanks for, posting on my blog mate! I shall email you some time. I did not know that.
I’m bookmarking this for future reference. Valuable content.NaN