Continuous Integration using Jenkins with Gitlab and JIRA

Continuous Integration using Jenkins with Gitlab and JIRA

Before beginning to this article make sure Jenkins Server, Gitlab Server and JIRA are already setup and running.

Step 1: Integrate Gitlab with Jenkins:

Generate Access Token in Gitlab: Gitlab → User Settings → Access Token

Configure Global Key in Jenkins: Jenkins → Credentials → System → Global Credentials → Add Credentials

Add the API Token generated in previous steps. Once added it will appear in Global Credentials listing.

Configure Connection Between Jenkins and Gitlab: Jenkins → Manage Jenkins → Configure System → Gitlab

Step 2: Configure Jenkins Build Triggers and Post-Build Actions

Go to Jenkins → → Configure → Build Triggers

Above Gitlab CI Service URL will be used inside the Gitlab as Webhook URL

Go to Jenkins → → Configure → Build Triggers → Advanced → Secret Token → Click Generate

This token will be used inside Gitlab as Webook

Go to Jenkins → → Configure → Post-build Actions

This will enable the feedback from Jenkins to Gitlab once Build has been completed.

Step 3: Configure Gitlab Webhooks

Go to Gitlab → Projects → → Settings → Integrations

Add Gitlab CI Service URL and Secret Token Generated and Click on Add Webhook.

Once Webhook has been added we will be able to test the events from here.

Here is an example of after clicking the Push events button

Gitlab shows the status that Jenkins is creating the Build from Commit.

Inside Jenkins you will see that Build has been triggered from Gitlab

After success completion of Build Giltab displays the status of Build.

Step 4: Integrate JIRA with Gitlab:

Gitlab → Admin Area → Service Templates → JIRA

Add your JIRA instance credentials

After saving above configuration your Gitlab Project will be able to Interact with all JIRA Project. JIRA issue in GitLab will automatically add a comment in JIRA issue with the link back to GitLab.

While commit source over Gitlab don’t forget to mention the JIRA issue in comment as follows:

Mentioning JUI-3 as JIRA Issue Id in Gitlab Commit

Link of Gitlab Commit/Merge in JIRA

Comment on JIRA when source is committed on Gitlab

For more detailed reference please go through GitLab JIRA integration documentation.