Example : Jenkins and GitLab integration

The objective of GitLab and Jenkins integration is to allow us to trigger a Jenkins build when:

  • A code is pushed to a repository
  • A merge request is created.

In this tutorial , we will try to integrate GitLab and Jenkins.

GitLab Configuration

Create build user and access token at Gitlab

To create a user and access token go to

Profile Settings >>> Access Tokens.

Over there create a new user named “jenkins-user” then we have to create a personal access token and save.

Now you have to copy the access token and save somewhere, because it is visible only one time , so its very important to save it !!

Jenkins Configuration

Add Gitlab credentials to Jenkins

Now we will add a new credential of the type GitLab API token In the Jenkins’s System credentials. Paste the API token copied earlier in the ‘API Token’ field and save them.

Configure Jenkins server

To start configuring the Jenkins server we have to install :

To configure the Jenkins server go to :

Manage Jenkins >>> Configure System

In the ‘GitLab’ section :

  1. set the GitLab server URL in the GitLab host URL field
  2. select the added Gitlab credentials from the credentials drop-drown.

Configure Jenkins project

After configuring connection between Jenkins and GitLab. now we have to create a job. For configuring a Jenkins project , try to follow the next steps :


After inserting the GitLab connection we will setup the git repository


Now we will try to choose the event that start the pipeline (example push events)


Webhook Configuration using Gitlab

Now we will create GitLab project or choose an existing one. Then :

Project >>> Integrations >>> Jenkins CI.

  1. Enter the Jenkins project URL in the given ‘URL’ field
  2. select the trigger events from the list and save, as a result, a new web hook will be added accordingly

Here we picked the Push events, Now If you push a commit to the repository of the project ,Jenkins job start running !! for code quality , try to read this tutorial : Example of SonarQube with Jenkins using Docker Images

Marwen Mselmi
Author: Marwen Mselmi

Founder of Javatuto.com, love Java and open source stuff. Follow me on Linkedin.

Leave a comment