JIRA issue on jenkins job failure - jenkins

I want to integrate Jenkins with jira so that, as soon as a build fails an issue is created in jira. I have already tried jira create issue in jenkins but its not creating any issue

Look at this question: Execute Shell Script after post build in Jenkins
The accepted answer by #Daniel Magnussen refers to http://wiki.hudson-ci.org/display/HUDSON/Post+build+task This is what you need as well
When the build fails, just send a curl request to jira's rest api to create a new issue. Here is some info on how to create the issue with curl:
https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-create-issue

Related

How can I update an issue status in JIRA via Jenkins?

I am trying to connect JIRA via Jenkins and updating the JIRA Issue status once my Jenkins Job is triggered and successfully executed or failed . I am looking forward to use Jenkins POST Build Actions. Also before that I am also facing an validating credential issue .
I have tried using JIRA Plugin , but I dont see and JIRA Issue Updater field in my Jenkins Job created .
I expect
A. To connect and Validate JIRA Plugin
B. Update my ticket status in JIRA post JOB execution
If you are using a Freestyle Job there is a post action called JIRA: Update relevant Issue
If you are using Jenkinsfiles you should look at the documentation here.

Can Jenkins used with python project?

I'm developing a web application using python django. I want a CI service which can automatically pull the latest code from my github and run some test then deploy. I'm not familiar with CI, after searching for a while I found Jenkins seems to be a good solution. Can Jenkins be used for this?
Jenkins can be used with any project.
Regarding pulling the latest code, add the Jenkins GitHub plugin in order to be able to check "Build when a change is pushed to GitHub" under "Build Triggers".
That will launch your job on any new pushed commit on the GitHub repo.
From there, a Jenkins job can execute any command that you would do in command-line, provided the agent on which said job will be scheduled and executed has the necessary tools in its PATH (here python)
An alternative (which does not involved Jenkins) is to setup a webhook and a listener on your server which will detect a "push event" sent by said webhook.

jenkins + sonar + github integration

Problem: I am setting up jenkins + sonar + github integration for automatic pullrequest static code check through sonar.
My Configuration:
Installed Sonar with github
Installed jenkins
In jenkins post-build action I have the following properties
-Dsonar.github.login=bhuwang
-Dsonar.github.repository=company/repo
-Dsonar.verbose=true
-Dsonar.analysis.mode=preview
-Dsonar.issuesReport.console.enable=true
-Dsonar.forceUpdate=true
-Dsonar.github.login=gitusername
-Dsonar.github.oauth=token
Token was generated from my github account.
In this link I have read that I have to provide the following properties while running sonarqube:
I have added all except sonar.github.pullRequest properties. I don't know how do I get this property value dynamically. Seems like above four properties are must to work properly.
Edit: I have found the way to add property -Dsonar.github.pullRequest=pullrequestNo
And the good news is it is working perfectly fine now with hardcoded pull request no. but I need the dynamic way to get the pull request no.
Does anyone know how to get the pull request no. dynamically inside jenkins.?
I have found that pull request builder will work but no luck at my end. I am not able to use pull request builder environment variables inside sonar properties.
https://issues.jenkins-ci.org/browse/JENKINS-24590
Finally I am able to solve this issue. Here is the detail:
Install Sonar with GitHub plugin.
Install Jenkins with the following plugins
GitHub Pull Request Builder
SonarQube Plugin
GIT plugin
GitHub plugin
Follow this link to setup pull request builder plugin: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin#GitHubpullrequestbuilderplugin-EnvironmentVariables
Global Jenkins System Setup:
Goto Manage Jenkins -> Configure System
Configure jdk
Install sonarQube Runner
Configure Sonar
Git WebHook Setup
PullRequest Builder Setup
Create Free Style Jenkins job
add github url to GitHub Project section
Setup Source Code Management Section
Setup Build Trigger
Setup Sonar for post build actions
In the additional properties section provide the following sonar properties
-Dsonar.sourceEncoding=UTF-8
-Dsonar.analysis.mode=preview
-Dsonar.github.repository=company/repo
-Dsonar.github.login=gitusername
-Dsonar.github.oauth=oauthtoken
-Dsonar.host.url=sonarhostedurl
-Dsonar.login=admin
-Dsonar.password=pass
-Dsonar.github.pullRequest=${ghprbPullId}
${ghprbPullId}: this will be provided via github pullrequest builder plugin
Note: The job should be triggered through pullrequest builder plugin otherwise ${ghprbPullId} will return blank. If you run the job manually this will not work for that you have to pass this ${ghprbPullId} property as a build parameter. If you want to check the environment parameter available follow this Git environment variables for use in executing Jenkins shell scripts
I hope this helps.
Too long for a comment so I'll have to write it here.
After some research on the web I've found a question on SO from someone a few steps ahead of you in the process of trying to setup a similar system, here. They're trying to get this all working with Maven, I'm not sure if you are also, but either way you can then see the link they've been using to help them with their script:
https://github.com/SonarSource/sonarqube/blob/master/travis.sh
This shows they need to write a script that will retrieve the pull number dynamically for them. I think you may need to follow a similar approach and write a script that will retrieve the number for you, I believe one of the github conf files keeps track of the current pull request number for its own tracking purposes.
Not really as straight forward an answer as you might have been hoping for, but hopefully this is new information that helps you get there.
See my project's implementation Jenkins + SONAR + Github with code at
https://github.com/lqtruong/ci

Gitlab and Jenkins integration novice

What do you put into the system hook URL? I see a lot of examples but they look like JSON scripts to me.
I'm trying to configure gitlab to hook jenkins to create projects when projects are generated in gitlab. I'd also like builds to be run when a merge (pull) request is generated for a repo.
I've followed the steps outlined here for the gitlab hook plugin:
http://doc.gitlab.com/ee/integration/jenkins.html
But it's still not generating builds on push requests. Perhaps i don't have something setup right?
I have also tried and failed to configure Gitlab to integrate with Jenkins by following the instructions at http://doc.gitlab.com/ee/integration/jenkins.html#jenkins-service
For me the reason was that I didn't have Gitlab EE installed. The page specifically states: "The Jenkins project service code is only available in GitLab EE"
I discovered by chance my answer. In gitlab under the project settings you can add the following hook to trigger a build on a pull request or commit.
http://gitlab.example.com/job/example_project/build?token=UserToken.
I believe I saw it in Jenkins.
Now i've installed the gitlab plugin and i've tried the build_commit? hook and some other hooks but i was running into other errors such as asking for repo location when i've provided it. This does the trick though and i'm happy enough for now.

Create a job in Jenkins automatically when a repo is created in Phabricator

I have a repo in phabricator and cloned in my local machine.
Now I want to create a new Jenkins job automatically after creating a new repo in Phabricator. Jenkins API is available to create a new job remotely.
According to Jenkins:
To create a new job, post config.xml to this URL with query parameter name=JOBNAME. You need to send a Content-Type: application/xml header.
I can create a job by the following command using terminal.
curl -X POST -H "Content-Type:application/xml" -d "<project><builders/><publishers/><buildWrappers/></project>" "http://ip:port/createItem?name=AA_TEST_JOB1"
Question: How can I run the command by Harbormaster to create a Jenkins job and also send config.xml file for the configuration of that new job?
Guy Warner (http://www.guywarner.com/) has done a lot of work to show how this is possible. You can visit his blog post for more details: http://www.guywarner.com/2014/05/integrating-jenkins-and-phabricator.html (part 1) and http://www.guywarner.com/2014/06/part-2-integrating-phabricator-and.html (part 2).
The basic idea is that your Harbormaster Build Plan will make an HTTP request to your Jenkins instance.
We used his tutorials to setup almost 100 builds that trigger from Phabricator based on different types of changes.
Actually, there is no settings or automatic way to create a Jenkins job after creating a new repo in Phabricator.
I've solved this editing Phabricator php codes. Simple way is to call the Jenkins API from php codes after creating a repo.

Resources