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:
- Install the plugins.
- Use the job DSL to create the job. The DSL is in the wiki and in the repo.
In GitLab:
- Create a API token. You will find it at
/profile/personal_access_tokens
- Add a webhook. You will find it at
/root/violations-test/settings/integrations
. Point it athttp://user:password@jenkins:8080/generic-webhook-trigger/invoke
. - 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:
Pipeline approach
I just use curl, GitLab plugin and Violation Comments to GitLab Plugin to implement it.
Here is what you need to do to use this workflow.
In Jenkins:
- Install the plugins.
- Create a pipeline job. The pipeline script is in the wiki and in the repo.
In GitLab:
- Create a API token. You will find it at
/profile/personal_access_tokens
- Add a webhook. You will find it at
/root/violations-test/settings/integrations
.