Continuous Integration with GitLab and Jenkins

My client recently started using GitLab. I did not find the plugins needed to properly verify merge requests. Here is what I wanted to do:

  • Trigger on merge requests events.
  • Merge, compile, test and run static code analysis on it.
  • Report static code analysis results to GitLab.

When fiddling with this I came up with a Job DSL solution and a pipeline solution. Here is how they work.

Job DSL approach

I developed a couple of Jenkins Plugins to do this.

I also use the HTTP Request Plugin and Conditional BuildStep Plugin.

Here is what you need to do to use this workflow.

In Jenkins:

  1. Install the plugins.
  2. Use the job DSL to create the job. The DSL is in the wiki and in the repo.

In GitLab:

  1. Create a API token. You will find it at /profile/personal_access_tokens
  2. Add a webhook. You will find it at /root/violations-test/settings/integrations. Point it at http://user:[email protected]:8080/generic-webhook-trigger/invoke.
  3. Make sure you are authenticated, in this request, with a user that can view any jobs that should be triggered.

The GitLab merge request will then be commented like this:
alt

Pipeline approach

I just use curl, GitLab plugin and Violation Comments to GitLab Plugin to implement it.

Violation Comments to GitLab pipeline
Here is what you need to do to use this workflow.

In Jenkins:

  1. Install the plugins.
  2. Create a pipeline job. The pipeline script is in the wiki and in the repo.

In GitLab:

  1. Create a API token. You will find it at /profile/personal_access_tokens
  2. Add a webhook. You will find it at /root/violations-test/settings/integrations.