Alexandre Miziara
Alexandre Miziara

Reputation: 316

How to trigger a git hook in server-side using GitLab

So I need to make a validation in some files names during merge from any branch to develop branch in my repository. I searched a lot but only examples I found is to integrate Jenkins and GitLab to build project in each commit/push, etc.

But is it possible to configure somehow a pre-push script to be executed (maybe by Jenkins) in server-side so each time a push is received to merge something to this develop branch I execute my custom script? I don't want to build it, only make this validation of files to be able to stop or not the push request.

Upvotes: 4

Views: 2069

Answers (1)

VonC
VonC

Reputation: 1327784

The Jenkins GitLab hook plugin is there to listen and receive each push events sent to GitLab (for a given repository).

From there you can trigger any Jenkins job you want (not necessarily a build job) with the script you want to execute.
If you want to execute said script before merging to the develop branch, you need to make the webhook monitor push events done on a dedicated branch (that would trigger the script which would then merge to dev and push)


If your GitLab instance is on-premise, then you can consider setting up a "Custom server-side Git hooks", like:

  • a pre-receive hook which could invalidate the push if it does not meet some criteria
  • a post-receive hook which could modify some files (possible adding a new additional commit)

Upvotes: 2

Related Questions