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
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.
 
    
    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
 
    
    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.
