4

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.

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

8 Comments

sorry, but I didn't understand very well what you suggested. What you mean by "dedicated branch"? I understand that I have to configure webhook to send push events to jenkins by using this plugin, right? But can I reject push in my script? (like e.g. using pre-push hook)
@AlexandreMiziara "I understand that I have to configure webhook to send push events to Jenkins by using this plugin, right?": no, the plugin is there to listen to a webhook, which means the push already took place on GitLab side, which in turn notifies any listener of that (already completed) push. Hence my suggestion to push to a dedicated branch (ie different from develop): your script will then be triggered (by the Jenkins listener) and can decide to push to the actual target branch (develop) or not (which would be "blocking the push" -- to develop)
now I understood your idea...I don't think this would be possible in my case. You know if we can somehow execute script before push? Or this would be only possibly using pre-receive hook direct in server side (gitlab)?
@AlexandreMiziara "before push": that is a client-side script, which is not convenient, as it needs to be distributed (to clients), and can be bypass. "pre-receive hook": that is not possible on GitLab side (if you are talking about gitlab.com), it could be possible on a private on-premise GitLab instance. By the way, why pushing to an intermediate dedicated branch is not possible in your case?
@AlexandreMiziara The documentation you mention (docs.gitlab.com/ee/administration/custom_hooks.html) is valid if you have access to and control over the GitLab server instance.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.