Jenkins: GitHub hook trigger for GITScm polling - jenkins

I try to configure Jenkins. I want a simple behavior: trigger a build on new pull request.
So, I created a job and configured it, but I checked the checkbox for:
And as you can see nothing is dropped down.
If I click the question mark on the right side, I see:
If jenkins will receive PUSH GitHub hook from repo defined in Git SCM
section it will trigger Git SCM polling logic. So polling logic in
fact belongs to Git SCM.
But where is the "Git SCM section"?

You need to configure the webhook on your GitHub repository. Then, on every commit push, Jenkins will be notified.
So, open your repository in the browser, then go to Settings > Webhooks and add a new one.
Then, enter the URL of your Jenkins instance followed by /github-webhook and select the other options depending on your needs:

I was also frustrated with this topic, this was needed for me to get job triggering working from GitHub MERGE:
GitHub repo -> Settings -> Webhooks -> push type webhook with URL:
http(s)://host:<port>/github-webhook/
For me, last slash was REQUIRED, did not work without it
In Jenkins System Settings, add GitHub Server, credential for it and [x] Manage hooks
Use Test settings button to test it works
In Job configuration, Source Code Management -> Git, add repo and credentials
Under Build triggers: [x] GitHub hook trigger for GITScm polling
In GitHub webhook settings, click webhook and it shows logs how it worked under "Recent Deliveries" title

It is a source code management section (before triggering section),
uncheck "none" case and check git ou github case(depend to your version) and fill the input field with your git repo url and credential

Related

Jenkins freestyle project not getting triggered by github webhook

So, this is what I've done so far:
Created GitHub personal access token with God's permissions (except delete repos)
Associated personal access token in Jenkins > Manage Jenkins > Configure System> GitHub , I test it and says "Credentials verified for user dim_user, rate limit: 4998"
Checked "Manage hooks"
In Source Code Management I set it like this:
Repository URL: git#databases.github.com:ORG_NAME/bootcamp_databases
Credentials: - none - (I'm using local's Git config file and id_rsa private key)
Also in "Build triggers" I've checked "GitHub hook trigger for GITScm polling" which refers to the old "Build when a change is pushed to GitHub"
I am able to Manually build it and it works perfectly (gets source code from GitHub and deploys everything)
In the project's GitHub Hook Log it shows: "Polling has not run yet"
GitHub recent Webhook deliveries are successful
Jenkins Logs (jenkins.err)
Jul 17, 2019 10:11:31 AM org.jenkinsci.plugins.github.webhook.subscriber.DefaultPushGHEventSubscriber onEvent
INFO: Received PushEvent for https://github.com/ORG_NAME/bootcamp_databases from XXX.XX.115.71 ? http://XXXXXXXX.ngrok.io:8080/github-webhook/
Project item: Freestyle
Jenkins Version: 2.176.1
I've tried these and did not help:
https://issues.jenkins-ci.org/browse/JENKINS-35132
https://issues.jenkins-ci.org/browse/JENKINS-41377
Actual:
Expected:
To actually fetch the code when pushing to GitHub and triggering the jenkins build.
What am I missing, all of the above points were solutions on other stackoverflow questions but so far not good.
I think your error is here:
Build triggers" I've checked "GitHub hook trigger for GITScm polling
In Jenkins an others c.i servers there are two techniques to detect scm source changes:
Polling: Jenkins asks periodically to github if source code has changes ( i.e git clone every minute and compare )
webhook: Github notify to your Jenkins when an event is detected in git platform( github, bitbucket etc). This is more cheap and does not need check changes at predefined interval (polling)
My advice is to try with webhooks instead scm polling. Also polling is an outdated technique.

Jenkins not triggered by github-webhook

I have taken these steps:
Check "GitHub project" and set up the project
Check "GitHub hook trigger for GITScm polling"
Setup connection to private repository with user/password
If I build manually, it works
In GitHub, create a webhook on push to http://my_jenkins_url/github-webhook/
Whenever I commit something, it shows that a webhook has been sent and I get a 200 response code (on github)
But no build is triggered on Jenkins. The GitHub Hook Log says: "Polling has not run yet.". How can I make it "start"? How can I further debug this?
EDIT: I have not added a GitHub Server in Manage Jenkins -> Configure -> GitHub since I ran into issue with the authentication (but that would be a different question). Is this required for github webhooks?
EDIT2: I figured out how to add a GitHub API to the Jenkins config (using Personal Access Token with git hook access enabled). But it doesn't seem to make a difference.
I found how to fix it properly.
First. set Jenkins logger at Jenkins manage > system log
add log recoder, with this configuration
hudson.plugins.git.GitStatus - All
com.cloudbees.jenkins.GitHubWebHook - All
org.jenkinsci.plugins.github - All
Second. Hook trigger again.
and check logger again. In my case, the logger says
Skipped {ProjectName} because it doesn't have a matching repository.
Third. Check the webhook url where the webhook request exactly came from.
it will be specified at logger like this:
Received PushEvent for https://github.com/{username}/{reponame} from {ip} ⇒ http://{your jenkins url}/github-webhook/
Fourth. Again go to jenkins project configuration,
check whole github urls are exactly same as https://github.com/{username}/{reponame} at step 3.
No .git at last.
I hope this answer helps you. Thank you

How to trigger Jenkins job automatically when new tag is added to a remote branch

These days I am trying to configure a Jenkins job which will be triggered by tag added to remote branch. Following are the steps what I did:
Added hook on github side and set the event to "Branch or tag creation" (I can see the hook is correctly triggered on github (enterprise version)).
Create freestyle jenkins job (pipeline should be similar), in the git section configure git as below.
Check "triggers "GitHub hook trigger for GITScm polling" in Build triggers section
Then I try to change something and add tag to branch, and push to remote.
But still cannot trigger the job run on Jenkins automatically. I have searched a lot but still cannot make this work.
But when I change the event to "Pushes" on github side (others keep the same), then the job can be triggered.
Anyone have the idea? Thanks.
And how about Jenkin2 pipeline? No git section in job configuration.

Bitbucket webhook to trigger Jenkins job

I'm having trouble getting my webhook in bitbucket server to start a Jenkins job. I've read through the other answered questions on here and can't get it going.
Bitbucket setup:
No special plugins installed
In repository settings I have a webhook set up
URL: http://[my jenkins url]/bitbucket-hook/ (yes I have the trailing slash)
Repo Push event selected
Jenkins setup:
Bitbucket plugin installed
Created new job
Set SCM to Git and added repo details
Set branches to build to either ** or refs/heads/rob-jenkins (a branch in git)
Build when a change is pushed to bitbucket selected
What I do:
I make a change to a file in rob-jenkins branch, push and the job is not started in Jenkins.
What I see:
In bitbucket, repo settings, webhooks I can see the webhook fired as soon as the commit is pushed. It has a 200 http status code, response body is empty.
In Jenkins I've set up a logger for
com.cloudbees.jenkins.plugins.BitbucketHookReceiver
com.cloudbees.jenkins.plugins.BitbucketJobProbe
com.cloudbees.jenkins.plugins.BitbucketPayloadProcessor
com.cloudbees.jenkins.plugins.BitBucketTrigger
And when I look at those logs I can see only 1 entry from com.cloudbees.jenkins.plugins.BitbucketHookReceiver
Received commit hook notification : {"eventKey":"repo:refs_changed","date":"2018-05-22T12:18:11+1000","actor":{"name":"xxxxxx","emailAddress":"xxxxxx#xxxxxx.com","id":53,"displayName":"xxxxxx","active":true,"slug":"xxxxxxx","type":"NORMAL"},"repository":{"slug":"xxxxx","id":1,"name":"xxxxx","scmId":"git","state":"AVAILABLE","statusMessage":"Available","forkable":true,"project":{"key":"SS","id":2,"name":"xxxxx","description":"xxxxxx","public":false,"type":"NORMAL"},"public":false},"changes":[{"ref":{"id":"refs/heads/rob-jenkins","displayId":"rob-jenkins","type":"BRANCH"},"refId":"refs/heads/rob-jenkins","fromHash":"1d9ad42fa404c893853094b0072e5b839f787589","toHash":"9bf7dc873f355259e4338ee80afbd246ecbb48a9","type":"UPDATE"}]}
There are no other entries in the log.
In the job itself, the BitBucket Hook Log screen just says "Polling has not run yet."
No idea why it isn't triggering the Jenkins job... what am I missing?
I've tried setting the Poll SCM manually and that didn't make a difference.
I've done a manual build and it works fine
as commented by #tomas-bjerre the resolution was to use a different plugin
I would recommend using thie plugin instead: github.com/jenkinsci/generic-webhook-trigger-plugin – Tomas Bjerre yesterday
No plugin needed. Just add a post-recieve hook under your repo in Bitbucket. On Jenkins, under Build Triggers, Trigger builds remotely (e.g., from scripts) Trigger builds remotely (e.g., from scripts) and specify an Authentication Token. A bash or python script can be used for the hook. Anytime a git push is run (not just a commit), you trigger a build!

how to specify which branch gets build in jenkins from a webhook in bitbucket

I installed the bitbucket plugin in Jenkins, and made the following changes:
I added the webhook on the bitbucket repo in the following format:
http://JENKINS.SERVER:PORT/bitbucket-hook
Under build trigger enabled Build when a change is pushed to BitBucket
Under Source Code Management selected GIT; I defined which branch to build: foobar
So my question is, I want the build to be triggered only when there is a commit on that specific branch foobar!
How do I do that?
Do I need to specify anything else on the bitbucket side?
Tnx,
Tom
In Job Configuration -> Source Code Management -> Branches to build
Specify which branch you want to trigger for build

Resources