0
votes

I have a GitLab project with a WebHook which triggers a Jenkins job. As of now, I have enabled Push Events to trigger the Jenkins job. So, whenever I push code from my local computer to remote repository, the Jenkins job is automatically triggered and the job successfully builds my codebase by checking out the code from GitLab's master branch.

Is there an option using which I can have the Webhook trigger Jenkins build only on such push events whose commit message contains a specified string like "build jenkins"?

I assume the answer to above to be No as the Webhook has already been configured and can't be stopped. However, I read slightly about creating custom hooks on the remote repository which can help me in above. If that is true, how can I do that and where do I need to write the custom hook and how to use it?

Thanks

1
Are you using gitlab hook plugin ? You can read the commit message in webhook payload and decide to run your build or not. github.com/jenkinsci/gitlab-hook-plugin/blob/master/README.mdben5556
Thanks @ben5556. I had a quick look and looks like I am not using gitlab hook plugin build_now. Will try that out. However, what I wanted to know was that will this trigger the Jenkins job to start or not. Would it be like it will start the job and then read the commit message in webhook payload and abort the job or would it be like it will not start the job at all?letsbondiway
What I’d recommend is have a single job which is triggered by the gitlab hook and then trigger your actual job based on the commit message. You can also extend this to trigger any of your other jobs based on the repo, branch and commit message from which the webhook came.ben5556
We use a different plugin - Generic Webhook Trigger Plugin and it works great! Check it out wiki.jenkins.io/plugins/servlet/…ben5556
Perfect. That worked @ben5556. Thanks!letsbondiway

1 Answers