Gitlab and Jenkins integration novice - jenkins

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.

Related

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

Configuring gitlab hook plugin

we've created a continuous integration workflow with Gitlab (v7.9.2) and Jenkins(v1.596.2). We defined a Jenkins job to build every push that is made to every repository on Gitlab with the Gitlab hook:
http://xx.xx.xx.xx:8080/gitlab/build_now
It's bad practice to let one job build all the tasks so we want to use the Gitlab-Web-hook plugin to define a template job witch creates a new job for every unknown repository that triggers the Web Hook, like described in the Gitlab-Web-hook plugin description under section Templates for unknown repositories.
The plugin can be configured to automatically create projects when the hook is activated by a GitLab repo unknown to Jenkins.
Now we have difficulties finding the right configuration, or even how to start integrating this plugin into the workflow. We spend a day searching for tutorials of default configurations on this subject and couldnt find any.
We hope the community can help us with this or set us off with some usefull hints, trics or tutorials. It's the last piece of the puzzle for us.
Thank you

GitLab and Jenkins integration

I've read the differences between Gitlab Community and Enterprise in this page: https://about.gitlab.com/features/
Based on that page I understand the integration with Jenkins is only available in the enterprise version. However, I've seen that using web hooks I can trigger builds in Jenkins when a push happens in Gitlab.
So my question is which is the difference between community and enterprise regarding the integration with jenkins?
On the merge request page, there is a state widget that shows the status of tests for that particular merge request, and on your project home page, there is test status badging. These two UI elements only show up if you enable a 'ci service' on the project. In community you can turn it on with Gitlab CI. In enterprise you can set it up to work with jenkins.
Based on that page I understand the integration with Jenkins is only
available in the enterprise version.
This is no longer true, the Jenkins GitLab Plugin (from a 3rd party) works to hook Jenkins into GitLab as a CI provider.
The wiki page has an example setup with lots of details you'll need to get it working.
This will give per-commit build/test status indicators in GitLab and also hook into the Merge Request system (both in the local repo and when merge requests come from forked repos).
You can also integrate GitLab with Jenkins using the Generic Webhook Trigger Plugin.
An example of integrating with that plugin, to perform static code analysis on merge requests, is available in the Violation Comments to GitLab Plugin wiki page.

Github Jenkins plugin with Github Enterprise

I have a Jenkins server with the following github plugins:
github-api
github
github-pull-request
I want to trigger a build after a merge (from a PR). This is because I have some build chains that I don't execute when building a PR so after a merge I need to create new deployment packages.
In the enterprise github there doesn't seem to be the same interface (as regular github) for webhooks I don't seem to be able define what events the github plugin (webhook) should listen for so I think its just the default 'push' event. Is this done somewhere else or is it a limitation of the enterprise version?
UPDATE
I have the github plugin working now but its builds for every push if I check the box. This disucssion https://groups.google.com/forum/#!topic/jenkinsci-users/gew5gWVDxw8 suggests that I should be able to use the git scm and github plugin together. Github plugin will register a change, scm plugin will poll server to determine if this change was tho the watched branch. I also tried this suggestion How can I make Jenkins CI with git trigger on pushes to master?
When I try and configure this no branch is ever built!
At least for me it's not exactly clear from your question what you actually exactly want.
It sounds like you only want builds to be triggered if there are some new commits on github on a specific branch.
If this is all you're looking for, you can just setup a webhook (Jenkins (Github Plugin)).
In you Jenkins job, just specify the branch you're tracking (Branches to build).
Assuming you setup github's hoock to jenkins correctly, this should trigger your build job on each commit on github enterprise.
If your hook doesn't seem to work: To check if and what your github server actually would send to your jenkins server, you can temporarily replace the url to your jenkins server in github's webhook with something like requestb.in (this will let you inspect github's hook payload)

Resources