Triggering a Jenkins build on GitHub merge event - github

I installed Github Plugin and set the Poll SCM to 1 minute.
Below is a picture of my configuration.
So when I commit on my repo, a minute after that the build starts.
On my github repo I created a webhook (but it timesout) and a service which doesnt work either (I think the problem is on my jenkins server).
But the checkbox "Build when a change is pushed to GitHub" is missing.

On the v1.25.1 release of the GitHub plugin, trigger Build when a change is pushed to GitHub has been renamed to GitHub hook trigger for GITScm polling.

Related

How can I configure Jenkins to run declarative Jenkinsfiles on GitHub Pull Request (PR) Close or Merge?

In a recent build of Jenkins (i.e., 2021-10-01 timeframe), how can I react to a GitHub pull request (PR) Close (or Merge) using declarative Jenkinsfiles and ONLY these "basic" Jenkins plugins?
GitHub plugin
GitHub branch source plugin
It seems that I should avoid GitHub Pull Request Builder since it can't react to PR close or merge.
Currently, everything works fine using a "GitHub organization" type project, when opening the PR and creating new commits on it (i.e., I see "continuous-integration/jenkins/pr-merge"), but when I click Close pull Request in GitHub, the Jenkins Build History doesn't react. I'm not sure why since, the "GitHub branch source plugin" states:
While the build triggers are often enough, you can set up webhooks to
automatically trigger builds when changes are pushed to your GitHub
repositories.

How to trigger a build in Go cd when a commit occurs in Github

I am wondering how I would configure a material in GoCD to trigger a build when a commit is made on the linked GitHub account.
You can follow "Integrating GoCD with GitHub" which uses a pull request workflow on GitHub side.
Each time a PR is done or updated on GitHub, the gocd-build-github-pull-requests plugin from Ashwanth Kumar would kick-in and build said PR, updating its status on GitHub after said build.

Jenkins 2 GitHub Organization: Automatic Rebuild for Pull Request

I am creating jobs using Jenkins Organization Folders.
I want to continuously build against pull request.
However, when I create a pull request, it will be built automatically only the first time.
Even if I add commit to pull request, Jenkins does not build automatically.
I expect that build will work again when the commit is added to the branch that created the pull request.
I am using the following version of Jenkins / plugin.
Jenkins: 2.89.1
GitHub Branch Source Plugin: 2.3.1
GitHub Branch Source Plugin has the following settings.
Discover branches: Exclude branches that are also filed as PRs
Discover pull requests from origin: Merging the pull request with the current target branch revision
Discover pull requests from forks: Merging the pull request with the current target branch revision
Also, although I am using Github Enterprise, I think that the configuration of webhook is okay as the build runs instantly when creating the pull request for the first time.
There is two way to resolve this issue
1)
You have to configure your github repository so it inform jenkins of a new version: yourRepo/settings/hook&service/service ( the best practice)
or
2) you can configure your jenkins jobs so it check for diff time-to-time if the repo have been update :
yourJob/configure/Scan Repository Triggers/Periodically -> 10 min
In my project, we configure both, with a Periodically check of once a day
If you were talking about GitHub Organization folder, then
there is a section where you can configure automatic branch triggering.

Jenkins using Github Webhooks

I am trying to setup Jenkins to simply detect a push event on a branch in a git repo, and when detected run a custom script which deploys the change.
I have setup Jenkins, installed the Github plugin and configured the webhook on Github.
This works the first time i push a change to that branch - I can see in Github the webhook being sent and in the Github log on Jenkins that a change is detected and the custom script is triggered by Jenkins so Jenkins access to Github is working.
Now if i make another change to the branch and push to Github, the webhook is fired but Jenkins does not detect a change.
In the Jenkins github log i see "No changes".
In my Jenkins job configuration i have added the Github project URL, selected GIT in the Source Code Management and put in the repo URL and added to the Branched to Build section as recommended by Jenkins:
refs/heads/mybranch
where mybranch is my branch name.
In the Jenkins Github Hook Log i can see, where REPO below is my private repo on Github.
Using strategy: Default
[poll] Last Built Revision: Revision 967ae07f677x581977h74t6c5362b31e8c45638
(refs/remotes/origin/mybranch)
/usr/bin/git --version # timeout=10
/usr/bin/git -c core.askpass=true ls-remote -h git#github.com:REPO.git # timeout=10
Done. Took 1.5 sec
No changes
Any ideas why subsequent push events are detected by Jenkins but no change is detected?
Is there any other config setting i need in the Job?
I could just setup a simple endpoint to receive the Github webhook and deal with it myself but i'd like to use Jenkins for this task and in the future.
Many thanks
Looks like there is an open issue for this problem with Jenkins git plugin 2.3.5
https://issues.jenkins-ci.org/browse/JENKINS-27332
So I followed this post to downgrade the git plugin to 2.3.4 and all is working now
http://blog.berg-systeme.de/2014/05/15/downgrade-jenkins-git-plugin/

Jenkins and Github with forked pr commits

I'm having an issue setting up Github and Jenkins CI.
When a forked PR commits changes, github doesn't notify jenkins, even if I've accepted the PR from a forked repo. Only when I merge a pr from a forked repo into master will github trigger Jenkins.
So the credentials and ability is there, but I can't find the option in github to force ALL commits to the original repo (including forked pr's) trigger the CI, anybody any suggestions?
The solution was to use the Github Pull Request Builder Plugin
There are instructions in the link above that worked for me. As well as the default instructions I had to also do this:
"This build is parameterized" and add string parameter named "sha1". When starting build give the "sha1" parameter commit id you want to build or refname (eg: "origin/pr/9/head").
and I didn't use github hooks
A post-receive hook in GitHub would post to any listening service any received commit.
It isn't limited to a particular branch.
However, Jenkins can be set to monitor a specific branch.
Unless, as mentioned in "How can I make Jenkins CI with git trigger on pushes to master?", you configure your Jenkins CI to Poll from GitHub (in which case, it will listen to said Github hook, instead of doing a git pull on a specific branch.
The GitHub pull request builder plugin mentioned by the OP Coombesy 's answer is one other way to make Jenkins poll GitHub.