Trigger building the Github's webhook head_commit in Jenkins - jenkins

I have configured a Jenkins Pipeline that correctly receives webhooks push notifications from GitHub, on push events.
The authentication is done through a deployment key.
Jenkins configuration seems to rely a lot on the concepts of branches and pull requests.
Given my workflow, which consists mostly of creating branches for any needs, and merge changes back onto master once things would look fine on the CI, I do not really care about seeing my builds categorized by branch or PR.
I would prefer to see builds based on commits' hashes. I do not see the need to tell Jenkins what branch I want it to match.
My current configuration is not selecting the commit revision I desire. I do not understand how it decides which branch or commit to build, once it receives a push notification. In Jenkins I have set the branch to **.
Checking the webhook payload, I noticed that it contains both the list of commits but also something called head_commit, with its id property being the commit's hash I want to see being built.
I would like Jenkins to do the following:
Check what's the head commit in the webhook notification (head_commit.id in the payload)
Build that precise commit, no matter the branch it is part of
Setting a green tick or a red cross beside the commit's hash on Github
Is this possible?

Related

jenkins generic webhook trigger git. Option Filter not working

I am using jenkins generic webhook trigger git. i want to trigger build only when a push is made on branch which starts with PO.Used optional filter as ^(ref\heads\PO-[a-z0-9_-])+$ but was not working, can someone please help. when Optional filter is blank. the build gets triggered on master branch.

Trigger Jenkins Job from Bitbucket on Pull Request

Hoping to gather insight from professionals. My end goal is to trigger a jenkins build whenever a bitbucket pull request happens. If anyone could give me an ELI5(explain like I am 5) answer it would be greatly appreciated. Sorry if this is the wrong format, I am new to jenkins and stackoverflow.
What I have done so far:
Created webhook in bitbucket and gave the url to my jenkins job. example: http://jenkinsURL:8080/job/boulevard-dev/generic-webhook-trigger/invoke?token=myPull_Request_Token
Pull request webhook trigger
In Jenkins, under source code management I have: Source Code Management Settings. This is currently fetching a ton of branches, failing, then building the master branch when the job starts?
For build triggers, other stackoverflow articles have pointed me to the "Generic Webhook Trigger". https://github.com/jenkinsci/generic-webhook-trigger-plugin
I am not entirely sure how this generic webhook trigger should effectively be setup? Hoping someone has experience using it and could explain what is needed.
This is what have seen referenced in other articles.Build Triggers settings Build triggers settings 2
Questions:
What does a correct setup / example of the generic webhook trigger look like?
Currently, my job triggers when a change is made to master or merged to master, how can I specify to my job that I want the bitbucket pull request branch to be built?
Also, I found this, not sure if its related to my issue or not? https://jira.atlassian.com/browse/BCLOUD-5814
As per your requirement, you can trigger a Jenkins build whenever a bitbucket pull request happens by following the below steps, in my case, it's working fine.
Step(1) - Configure Jenkins
(i) Add your bitBucket repo and branch to source code management
(ii) On build Triggers setup Poll SCM to * * * * * for run every minute to check pull request from bitBucket.
Step(2) - configure Bit Bucket Hook
(i) Go to settings and add a new hook, now setup pull request trigger as per your requirement.
Step(3) - Make a pull request and see the new job automatically triggered on Jenkins.

How to set up github webhook trigger on pushing in certain branch

I have Jenkins pipeline, and configured github webhook to trigger pipeline.
How to make triggering pipeline when the certain branch was pushed, instead of triggering pipeline by pushing to every branch ?
Webhook is generic for all, there is no filter on the side github or bitbucket, all you need to handle based on payload.
you can use Generic+Webhook+Trigger+Plugin,The plugin will allow you to parse certain data from the payload, and can conditionally trigger a build depending on the branch name.
Apply the filter with branch name
generic-webhook-trigger-plugin-specific-branch

Best way to apply regex policy to BitBucket Cloud commit messages?

Is there a way to implement a commit message policy on BitBucket Cloud?
From my understanding, the webhooks only work as commit notifications and can not intervene with the commits (to deny the commit if the commit message does not follow the set regex). For pre-commit hooks you would need BitBucket Server, right?
If that's the case, what about checking commit messages on a Jenkins build to fail the build if it contains a certain message that does not match the regex? Is that a viable option?
Another option, is there a local git config file where I could set the rules locally (even if they could be bypassed)?
I think you're confusing pre-commit hooks (which determine whether or not a commit can be made) with pre-receive hooks (which determine whether or not a specific remote will accept pushes). Bitbucket Cloud does not currently support custom pre-receive hooks, but Bitbucket Server does. Pre-commit hooks would need to be installed on every system where users make commits; those are not currently replicated, so you'd need everyone to manage them manually.
It sounds like Jenkins tests would be your best bet - check the commit message for the desired regex, and fail the test if the regex isn't there. That won't prevent people from making bad commits in the first place, but it will keep those bad commits out of the final product.

Build Jenkins project on BitBucket pushes and pull requests

I have a scenario where I'm setting up Jenkins for my app. I have BitBucket set up and firing appropriate webhooks.
I want to start a build whenever a push is made to the repo as well as whenever someone creates/updates a pull request.
I've looked at the BitBucket Plugin. It works good if I have the BitBucket webhook to fire for all pushes.
Then I added the BitBucket Pull request plugin to build on every pull request create/update. So I changed the BitBucket webhook preferences to fire on pushes and PR creates/updates.
Unfortunately, these plugins have conflicting settings, hence they cannot be used at the same time (as per my research, the minute I send custom webhooks from BitBucket, the first one stops working, but the second one works)
Has anyone been able to set this up correctly? Maybe there's a plugin for what I want, but I couldn't find it.
I want to keep writing a proxy in front of Jenkins to manage webhooks the last option, only if there really is nothing I can do.
Thanks for the help!

Resources