Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins pipeline for merge request in Gitlab

I've started lately to use Jenkins and i need some help with creating a pipeline.

I want to create the following pipeline: For each merge request from develop to master in Gitlab, Trigger a Jenkins job that run an end-to-end test, And merge the branches in Gitlab only if the test succeeded.

I have found the following article that gives me an explanation for most of the things that i need: https://vetlugin.wordpress.com/2017/01/31/guide-jenkins-pipeline-merge-requests/

I'm still looking for an answer for one question: How can Jenkins response to Gitlab with the result of the end-to-end test (Success/Fail), So Gitlab will know whether to merge to branches or not?

Please advise, Thanks!

like image 212
Omri Avatar asked May 21 '18 14:05

Omri


2 Answers

You do not tell us how Gitlab and Jenkins are connected, but I'll assume you use the Jenkins Gitlab plugin https://github.com/jenkinsci/gitlab-plugin. If you're not, maybe you should :)

With this plugin, you can 'integrate' more deeply Jenkins and Gitlab, and your Jenkins builds will send back to Gitlab the result of the build. You will see something like this https://raw.githubusercontent.com/teeks99/gitlab-plugin-wiki-images/master/Setup_Example_img/Result_commit.png. Build results are marked near the commit which has been tested.

In this case, for each merge request, you can check the "Merge if build succeed" button (see https://raw.githubusercontent.com/teeks99/gitlab-plugin-wiki-images/master/Setup_Example_img/Merge_progress.png) to auto merge the code when build is successful.

Look at the Jenkins Gitlab plugin README for more information and advanced setup, like test in your build the result of the merge, etc.

like image 139
daks Avatar answered Sep 21 '22 08:09

daks


So Gitlab will know whether to merge to branches or not?

GitLab itself does not have to be aware of this test result to, on its own decide to merge or not.

Your Jenkins job should, it the test is successful, call the right GitLab API in order to accept the MR (Merge Request).

like image 34
VonC Avatar answered Sep 22 '22 08:09

VonC