README.md 3.21 KB
Newer Older
1
# gitlab2jenkins
Jan Včelák's avatar
Jan Včelák committed
2

3
Gitlab2jenkins is a simple web application, which provides a bridge between [GitLab](http://gitlab.org/) and [Jenkins CI](http://jenkins-ci.org/) server.
Jan Včelák's avatar
Jan Včelák committed
4

5
The application exposes API, which looks the same as API used by [GitLab CI](http://gitlab.org/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.
Jan Včelák's avatar
Jan Včelák committed
6

7
It is written in Ruby (using [Sinatra](http://www.sinatrarb.com/) web micro framework) and is ready to be run on OpenShift cloud.
Jan Včelák's avatar
Jan Včelák committed
8

9
10
**Demo**, actually used in production:
[Knot DNS - gitlab2jenkins](http://gitlab2jenkins-fcelda.rhcloud.com/projects/1) at CZ.NIC Labs.
Jan Včelák's avatar
Jan Včelák committed
11

12
## Deployment
Jan Včelák's avatar
Jan Včelák committed
13

14
15
16
17
18
19
20
21
22
23
24
25
26
### Local deployment

Clone the repository, install required gems, edit the configuration, and start the server:

1. `git clone https://github.com/fcelda/gitlab2jenkins.git`
2. `cd gitlab2jenkins`
3. `bundle install`
4. edit `config.rb` (provide connection to MySQL database, GitLab URL, and Jenkins URL)
5. `foreman start`

### Deployment on OpenShift

Create the application directly using `rhc`. Notice that the application requires third party cartridge with Foreman.
Jan Včelák's avatar
Jan Včelák committed
27
28

```
29
30
31
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
Jan Včelák's avatar
Jan Včelák committed
32
33
```

34
35
36
## Configuration

### Configure target Jenkins job
Jan Včelák's avatar
Jan Včelák committed
37

38
39
40
41
42
43
44
45
46
47
1. Create new or update existing target Jenkins job.
2. In build configuration, enable *This build is parametrized* checkbox and add two parameters: `commit` and `branch`.
3. Set up source code checkout from GitLab Git repository and use `$commit` value as a branch to build.
4. In build triggers, enable *Trigger builds remotely* and set random *Authentication token*.

### Register Jenkins job in Gitlab2jenkins

Use provided `add_project.rb` script to register target Jenkins task.

For local deployment, run:
Jan Včelák's avatar
Jan Včelák committed
48
```
49
./add_project.rb "Project Name" "jenkins-job-name" "jenkins-secret-token"
Jan Včelák's avatar
Jan Včelák committed
50
51
```

52
53
54
55
For OpenShift deployment, run:
```
rhc ssh <appname> 'cd app-root/repo && bundle exec ./add_project.rb "Project Name" "jenkins-job-name" "jenkins-secret-token"'
```
Jan Včelák's avatar
Jan Včelák committed
56

57
The summary should be printed out. New secret token for authenticate to Gitlab2jenkins will be generated.
Jan Včelák's avatar
Jan Včelák committed
58
59

```
60
61
62
Project: Project Name
Jenkins: jenkins-job-name (token jenkins-secret-token)
Token:   gitlab2jenkins-generated-token
Jan Včelák's avatar
Jan Včelák committed
63
```
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

Open Gitlab2jenkis in web browser, link to the project should be on the main page.

### Configure GitLab to use the proxy

1. In the project settings in GitLab select *Services* and *GitLab CI*.
2. Enable the service by checking the *Activate* checkbox.
3. Set *Token* token a value generated by `add_project.rb` script.
4. 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>`.

## Troubleshooting

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'`