Jenkins not triggered by github-webhook - jenkins

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

Related

Github not triggering job when pull request is created to branch

I need to run a jenkins job when PR is created to my staging branch in github. The jenkins will run some test cases and return the results to github and after that only we can merge the PR to the staging branch.
I'm using GitHub pull request builder plugin in jenkins. But my job in jenkins is not getting triggered when PR is created. The webhook from github is show 200 status and its working to buid a jenkins job for github push.
I followed https://medium.com/#mreigen/integrate-jenkins-builds-into-github-pull-requests-33bc053d6210 steps.
Can anybody help me with This!
Check the Jenkins logs first.
For example, jenkinsci/ghprb-plugin issue 286 mentioned:
It looks like GitHub is sending the wrong kind of events.
The plugin only accepts pull_request and issue_comment events.
GitHub is sending a push event, so I am not sure but you might have configured the webhook using a different plugin?
Check your master config and make sure you are only telling the job triggers to use webhooks. Also, make sure you have checked the box in each job you want that says to build using webhooks.
Issue 603 involved the option "Use github hooks for build triggering", but mention an Hook URL issue.

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.

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!

Jenkins: Github webhook does not trigger any job

I try to configure Jenkins. I want a simple behavior: trigger a build on new pull request.
I cannot understand what I missed...
Jenkins version: 2.89.2
At https://ci.mysite.fr/configure :
Still no build triggered:
At https://ci.mysite.fr/job/test-back/configure :
On Github, Webhook is sent and well received by Jenkins:
Nginx Log says the same:
Help please!
Some things to check when debugging this sort of thing:
Check your Jenkins logs to see whether or not Jenkins is receiving the hook and deciding not to take action for some reason.
Check Jenkins security by clicking Manage Jenkins -> Configure Global Security. Open things up as much as you're comfortable doing and see if that changes anything.
Ensure that you're pushing changes to the master branch. For simplification, consider using ** as your branch specifier while you're getting this to work.
Ensure Git is properly configured on your Jenkins host by clicking Manage Jenkins -> Global Tool Configuration
Make sure the user whose credentials you provided can manage hooks and pull from the repo you're interested in.
Run the job manually in Jenkins, ensure that it works.
After you run the job, it should show up as an option in Protected Branches/Required Statuses. In your repo, click on Settings->Branches, select your branch in the Branches section, click Require Status Check to Pass before merging option, and your job should show up in the list which appears.
Webhooks are arguably the most difficult Jenkins feature to test without prior experience, because of gotchas like these (probably their list is incomplete):
New git commit / git push must be made for each pipeline build (repeating a previous one won't trigger a new build even if webhooks are already set up correctly - see below).
First build made after setting up webhook correctly must be manual (no bootstrap from the webhook itself is possible).
First build made after setting webhook correctly must succeed completely for the changes to take effect and for webhooks to start working. This will also cause Jenkins to miss all incoming requests made during the first build of a newly created pipeline.
More info
Please be warned that it is not possible to trigger a build using the same build conditions again (at least using a webhook). Therefore you might have a correct webhook setup already, but not find out that it works unless you create a new git commit and push it to the remote repo on Github. If your try to repeat some old push over and over again, by simply pressing the "Redeliver" button in the Recent deliveries section on Github's Webhooks / Manage webhook page, Jenkins will never move beyond the "poke" repo stage, as it requires SCM changes to be detected in order to trigger a new build:
Received PushEvent for https://github.com/mirekphd/<REPO_NAME> from <GITHUB_IP> ⇒ <JENKINS_URL>/github-webhook/
Apr 16, 2021 9:42:12 PM INFO org.jenkinsci.plugins.github.webhook.subscriber.DefaultPushGHEventSubscriber$1 run
Poked <REPO_NAME>
Apr 16, 2021 9:42:13 PM INFO com.cloudbees.jenkins.GitHubPushTrigger$1 run
SCM changes detected in <REPO_NAME>. Triggering #236
For further info on points 2) and 3): see original source.

Jenkins: GitHub hook trigger for GITScm polling

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

Resources