Gitlab2jenkins is a simple web application, which provides a bridge between GitLab and Jenkins CI server.
The application exposes API, which looks the same as API used by GitLab CI server. However all requests are processed and proxied to Jenkins. This is useful especially when your testing infrastructure is complicated and GitLab CI cannot satisfy your requirements — for instance, multi-host builds, triggering of other tasks, etc.
It is written in Ruby (using Sinatra web micro framework) and is ready to be run on OpenShift cloud.
Demo, actually used in production: Knot DNS - gitlab2jenkins at CZ.NIC Labs.
Clone the repository, install required gems, edit the configuration, and start the server:
git clone https://github.com/fcelda/gitlab2jenkins.git
cd gitlab2jenkins
bundle install
- edit
config.rb
(provide connection to MySQL database, GitLab URL, and Jenkins URL) bundle exec foreman start
bundle exec ./web.rb
Create the application directly using rhc
. Notice that the application requires third party cartridge with Foreman.
rhc app create <appname> ruby-1.9 mysql-5.1 \
http://cartreflect-claytondev.rhcloud.com/reflect?github=ncdc/openshift-foreman-cartridge \
--from-code https://github.com/fcelda/gitlab2jenkins.git
- Create new or update existing target Jenkins job.
- In build configuration, enable This build is parametrized checkbox and add two parameters:
commit
andbranch
. - Set up source code checkout from GitLab Git repository and use
$commit
value as a branch to build. - In build triggers, enable Trigger builds remotely and set random Authentication token.
Use provided add_project.rb
script to register target Jenkins task.
For local deployment, run:
./add_project.rb "Project Name" "jenkins-job-name" "jenkins-secret-token"
For OpenShift deployment, run:
rhc ssh <appname> 'cd app-root/repo && bundle exec ./add_project.rb "Project Name" "jenkins-job-name" "jenkins-secret-token"'
The summary should be printed out. New secret token for authenticate to Gitlab2jenkins will be generated.
Project: Project Name
Jenkins: jenkins-job-name (token jenkins-secret-token)
Token: gitlab2jenkins-generated-token
Open Gitlab2jenkis in web browser, link to the project should be on the main page.
- In the project settings in GitLab select Services and GitLab CI.
- Enable the service by checking the Activate checkbox.
- Set Token token a value generated by
add_project.rb
script. - Set Project url to project page in Gitlab2jenkins:
- In case of OpenShift, it will be something like
http://<app-name>-<namespace>.rhcloud.com/projects/<project-id>
. - In case of local deployment, it will be something like
http://localhost:4567/projects/<project-id>
.
- In case of OpenShift, it will be something like
New builds are pulled from Jenkins periodically. If it does not work, try updating the builds manually:
./update_builds.rb once
or rhc ssh gitlab2jenkins 'cd app-root/repo && bundle exec ./update_builds.rb once'