Jenkins using Github Webhooks - github

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/

Related

how do i automatically pull code from master to fork in azure repos using azure devOps pipeline

I was trying to pull the code from master to fork repository automatically through the azure pipeline. If any one know about this?
If you fork azure repo and want to automatically sync the Fork repo using VSTS Git, please follow below steps.
Supposed the url of original repo is https://dev.azure.com/{organization}/{project}/_git/test, and the url of forked repo is https://dev.azure.com/{organization}/{project}/_git/test_fork.
If you click "Clone" button in test repository, you will see below panel.
Clicking "Generate Git Credentials" button will show the following panel.
So we can use command git remote add upstream https://username:password#dev.azure.com/{organization}/{project}/_git/test to specify it as the upstream of test_fork repo in script.
Now creating a build pipeline using Microsoft-hosted Windows agents, setting the test_fork as the source.
Adding the Command Line task with below script.
git remote add upstream https://username:password#dev.azure.com/{organization}/{project}/_git/test
git fetch upstream
git rebase upstream/master
git push -f origin HEAD:master
Queuing a new build and it will succeed to sync the test_fork repo using VSTS Git.
You can also configure schedules for this pipeline. Now everything is done.
If you use GitHub repo, please refer to this thread for guidance.

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.

Triggering a Jenkins build on GitHub merge event

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.

Travis failed push but passed PR

How is it possible that Travis the build failed for the latest push but passed the Pull Request?
On this Gist, you could find the failed and passed output log of the npm run build command that Travis gives. You could also find the configuration of Travis and here below:
install:
- npm install
- npm install -g angular-cli
language: node_js
script:
- gulp html
- gulp scss
- gulp ts
- gulp node
- npm run build
node_js:
- "6.9"
cache:
directories:
- node_modules
- bower_components
Background
This repository is configured in Travis CI to run tests on two environments - named pr and push.
A Pull Request (pr) build will be named continuous-integration/travis-ci/pr and from the docs:
Rather than test the commits that have been pushed to the branch the pull request is from, we test the merge between the origin and the upstream branch. To only build on push events, you can disable Build on Pull Requests from your repository settings.
A push build will be named continuous-integration/travis-ci/push and from the docs
Travis only runs a build on the commits you push AFTER adding the repository to Travis.
Solution
Since the merge of your branch into the base branch passed tests for continuous-integration/travis-ci/push, updating your branch to include the latest commits from the base branch will get your branch passing tests. From the image above, the GitHub UI should allow you to Update branch from the Pull Request page.
Caveat
With branch protections in place, it should be unlikely that your branch fails tests while merging into the base branch succeeds.
Be sure that you confirm that whatever was broken was actually fixed. That is, did someone "fix the build" by disabling that failing test in the base branch? As a cautious person, I would cherry-pick fixes into your branch to verify the problem is resolved.
By a comment of #osowskit, I've found the solution of the problem. He/she said:
PR will merge your changes into the base branch and run CI tests. Push will run CI tests on the current branch. Merging the base branch into your branch will likely resolve your build test on the branch.

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.