Edit: I don't want to have two Jenkins jobs. We've tried it and our users get confused. We also need to maintain the code for two jobs.
In this case, the Generic Webhook Trigger will help you to configure execution only for specific webhook token.
You might also check those plugins Conditional Build Step and Run Condition they allow you to specify on which condition a job is executed.
Solution suggested before edit :
When a merge request is opened you want to prevent the push hook to be triggered.
In order to do so in your Jenkins Pipeline, in the Build Triggers section tick the following :
- Build when a change is pushed to GitLab. GitLab CI Service URL:
- Opened Merge Requests Events
In GitLab, go to Settings > Integrations and in your WebHook only tick the following :
This way you have a pipeline that is only triggered by Opened Merge Requests Events.
You said that :
The push hook executes the unit tests, and the MR hooks also executes the unit tests and the integration tests. This first execution is useless.
From my understanding you only need the MR hook to be triggered, since it also executes unit tests.
But if you need unit test to be executed on push events, you should create a new job or a new pipeline that is triggered only by Push Events.
In order to do so in your Jenkins Pipeline or job, in the Build Triggers section tick the following :
- Build when a change is pushed to GitLab. GitLab CI Service URL:
In GitLab, go to Settings > Integrations and in your WebHook only tick the following :
That way when a fix is pushed only this job or pipeline will be executed (only unit tests).
And when a Merge Request is created only the pipeline associated with this event is executed (all tests).