Jenkins GitLab integration with webhook

In this article I will show how to configure Jenkins server to work with GitLab with webhook. It means when developer will push some code in the repository where webhook already configured it will trig execution of Jenkins job. If you want to configure Jenkins with GitLab please use this link.

Jenkins server IP address:
GitLab server IP address:

Network topology:

In Linux or Windows desktop create SSH keypair which will be used to connect from desktop and from Jenkins. Content of the private ‘gitlab’ key will be used to connect to the GitLab server. Content of the ‘’ public key will be imported to out repository which will be created in the GitLab. Add key to ssh list.

$ ssh-keygen -b 2048 -t rsa -f gitlab -q -N ""
$ ls -la gitlab*
-rw-r--r-- 1 jamal.shahverdiyev 1049089 1679 Feb  7 15:59 gitlab
-rw-r--r-- 1 jamal.shahverdiyev 1049089  413 Feb  7 15:59
$ eval $(ssh-agent.exe -s)
Agent pid 860
$ ssh-add.exe gitlab
Identity added: gitlab (gitlab)
$ ssh-add.exe -l
2048 SHA256:39wtTMQC6+910gOV/0ilTUiuglmRyqiYqaPnytBEcnU gitlab (RSA)

In the GitLab create new repository and import ‘’ public key to this repository. Reset GitLab ‘root’ username password:

> vagrant ssh GitLab
[vagrant@localhost ~]$ sudo su -
[root@localhost ~]# echo 'R00tpass123' | openssl passwd -1 -stdin
[root@localhost ~]# gitlab-rails console production
Loading production environment (Rails 4.2.10)
irb(main):001:0> user = User.where(id: 1).first
=> #
irb(main):002:0> user.password = 'R00tpass123'
=> "R00tpass123"
irb(main):003:0> user.password_confirmation = 'R00tpass123'
=> "R00tpass123"
Enqueued ActionMailer::DeliveryJob (Job ID: 045c47d8-c866-4e23-9dc2-d336cf5608b3) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", gid://gitlab/User/1
=> true
irb(main):005:0> exit

Create new project:

Enter name of the project ‘jenkins-webhook‘ -> Visibility level ‘Private‘ -> Then press ‘Create project’ button.

In the top of page press ‘add an SSH key’ button:

Copy and paste the content of the ‘‘ file which we created before and add ‘Add key‘ button.

Go to the left side and press ‘Access Tokens

Enter name of token ‘JenkinsSRV‘, set expiration date, select access level and press ‘Create personal access token

Then copy the content of the ‘Your New Personal Access Token‘ to some secure place because you cannot copy this again.

First of all, update all plugins ang Jenkins itself. Then install ‘GitLab Plugin‘ from availables. Main menu Jenkins -> Manage Jenkins -> Manage Plugins -> Available tab and search ‘GitLab Plugin‘ -> Select Chechbox -> Download now and install after restart

Add new credentials for SSH and Token. Firstly we will add SSH private key credential for git. Go to the main menu -> Credentials -> global

Press Add Credentials -> Select SSH Username with private key -> Enter username ‘git‘ -> Select Enter directly and paste content of the ‘gitlab‘ private key (we created this key before) here -> Write some description and press ‘OK‘ button.

Add one more credential for ‘GitLab API Token‘. In the Kind select ‘GitLab API Token‘ -> In the API Token paste token which we created before in the GitLab server -> enter some ID with description and press OK button

Our credentials:

Configure connection between Jenkins and GitLab. Go to the Main menu -> Manage Jenkins -> Configure System

In the GitLab section uncheck ‘Enable authentication for /project end-point‘, enter connection name, enter GitLab url, select credentials for token, press Test Connection button (Result must be: Success) and press Apply/Save

Create new ‘Freestyle project‘. Go to the Main menu -> New Item and enter name ‘Jenkins-GitLab-WebHook-Trig‘ and press ‘OK‘ button.

Under ‘General‘ tab we must see connection ‘GitLab Connector

Under ‘Source Code Management‘ select ‘Git‘ -> Enter our project repo url, select git credential (SSH key created before), Enter Name origin, Enter refspec +refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/* and in the Branch Specifier enter origin/${gitlabSourceBranch}

In the Build Triggers section select ‘Build when a change is pushed to GitLab. GitLab CI Service URL:‘ and configure events as in screenshot:

In the ‘Post-build Actions‘ -> press ‘Add post-build action‘ and select ‘Publish build status to GitLab commit(GitLab 8.1 + required)‘ then press ‘Apply

For test purpose in the Build section new build Add build step Execute shell with some commands and then press ‘Save‘ button

Now we need configure GitLab to trigger builds. Go to the GitLab -> Select your project -> Press Settings -> Press Integrations

In the opened page enter url for Jenkins project like as the following syntax

Select ‘Push events‘ and ‘Merge Requests events‘, uncheck ‘Enable SSL verification‘ and press ‘Add webhook

Now from windows push somethings to see the result:

$ git clone git@
$ cd jenkins-webhook/
$ echo 'This is test Readme' >
$ git add
$ git commit -m "ADDED README"
$ git push

Output from Jenkins:

In the GitLab side look at the output. Go to your project name -> select Respository -> Commits

Look at the build status:


8 thoughts on “Jenkins GitLab integration with webhook

    1. Привет Костя. Точно не могу сказать в чем проблема. Обычно такие вещи происходили когда я не делал первое обновление для всех плагинов Jenkins-а.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s