2

I want to run a script when a merge request is generated from gitlab I 'think' I have 3 alternatives git hook gitlab webhook gitlab trigger

I would appreciate some advice from anyone who has done this before and what would be the best method

Thanks

GrahamL
  • 193
  • 10

3 Answers3

1

Git hooks are a native Git feature, git does not have a concept of merge requests - they are a feature of GitLab and competitor's platforms. As such a git hook will not meet your needs in this case.

GitLab webhooks are the solution you are looking for, as they can be triggered 'upon a merge request' being opened etc, see docs. They work by invoking a HTTP(S) endpoint, so if your script is set to run upon a request to this endpoint, or via some external build process (e.g. Jenkins) then these should meet your needs.

Triggers are for 'triggering' the rebuild of your project via GitLab (CI) (re-running a gitlab pipeline or external build), see docs. So they might meet your needs if the script to be run can be setup with gitlab CI or an external build process that can be integrated into GitLab.

Peter Reid
  • 4,169
  • 1
  • 33
  • 31
  • Thanks for the clarification - I will look into webhooks – GrahamL Jun 14 '17 at 08:06
  • Ok so I have a script running when a merge request takes place. What I want to do now is have my script stop the merge request proceeding. Is this possible? – GrahamL Jun 14 '17 at 13:19
  • With Gitlab CE, to the best of my knowledge and based on past experience - no, you cannot block a merge request based on the result of the invocation of a HTTP webhook – Peter Reid Jun 14 '17 at 13:21
0

Well I seem to have found a simpler answer

On the project settings page there are these options -

Merge Requests

Only allow merge requests to be merged if the build succeeds 
Builds need to be configured to enable this feature. 
Only allow merge requests to be merged if all discussions are resolved

Setting the first will block the merge proceeding if the build fails

Hope this helps others

GrahamL
  • 193
  • 10
0

Since Gitlab 11.4, you have the possibility in GitlabCI/CD to specify pipeline tasks to only trigger in the context of a merge request with the "pipelines for merge requests" feature.
So in your case you would specify specific scripts for this kind of pipeline.

chaiyachaiya
  • 2,257
  • 15
  • 18