Push to github doesn't trigger jenkins pipeline job - jenkins

I have configured jenkins pipeline job which should be triggered by github push but it isn't.
I specified github project
https://github.com///
I checked GitHub hook
trigger for GITScm polling And I run job manually.
I use ngrok so my localhost is visible. Important think is webhook is working fine because I tried do it with frystyle job and it was triggered.
Do you have any idea what is going on?

Related

BitBucket webhook triggers *all* Jenkins multibranch pipelines, even those who have that setting disabled

Context: We have a Jenkins 2.361.3 server and a local Bitbucket server with webhooks (on Push) that trigger multibranch pipeline jobs (declarative jenkinsfile mode) on Jenkins for every repo push. This works fine when we have a single multibranch pipeline job on Jenkins: the build is triggered for the correct branch.
New scenario: We want a second 'nightly' multibranch pipeline job on the same Jenkins server for the same Bitbucket repo, which we want to trigger on a fixed time every day for every branch that exists at that time. It should not trigger for repo pushes.
Actions taken: We created a second multibranch pipeline job, similar to the first one but now with a cron trigger in the jenkinsfile and this setting disabled: "Build when a change is pushed to BitBucket":
This setting is still enabled for the initial job.
Expectations:
On a repo push, only the initial job is triggered. The nightly job does nothing.
When the cron time hits, the night job is triggered.
Actual:
On a repo push, both jobs are triggered. (also after Jenkins restart)
Additionally, the cron trigger works as expected.
Question: How to configure this system so that a repo push only triggers the initial job and not the nightly job?
It looks like the combination of BitBucket plugin (v223) and Multibranch Pipeline plugin (v716) does not adhere to the "Build when a change is pushed to BitBucket" setting.
Experiments performed:
Disabling the "Build when a change is pushed to BitBucket" setting for both jobs (and restarting Jenkins) --> both jobs are still triggered by a repo push
Remove the webhook from BitBucket and configure 'polling SCM' for both jobs --> this works but polling feels suboptimal and adds performance hits to the server.
We solved it using the “Suppress automatic SCM triggering” property in the ‘Branch Sources’ section of the Jenkins configure page for the job, as explained here.
The ‘Scan multibranch pipeline trigger’ setting only controls the scans (even though the text says ‘build’), and this will cause a trigger. The Suppress property lets a certain job ignore a webhook or scan trigger. And then the job is only triggered by its cron-trigger, which is what we wanted.

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.

How to trigger jenkins job that execute automation test scripts when code is pushed in development server?

I am new to Jenkins. I have development code repository at bitbucket and another test script code repository at bitbucket. Now I have setup a Jenkins job by linking test code repository. Is there any way to trigger a build when code is pushed in develop repo?
I tried many times by pushing change in develop repo, but it does not triggers the jenkins job.
You can configure the Jenkins trigger as an SCM poll.
You will have to enter a cron expression for the polling time period, like:
*/5 * * * *
This means polling from 5 to 5 minutes. If any change is detected, then the build is triggered.
You can add the BitBucket Plugin to your Jenkins instance. It will allow you to configure a webhook in BitBucket that will then trigger any Jenkins job listening for that webhook. The plugin's page has a detailed breakdown, but the basics are;
In your repo in BitBucket, create a new Webhook using your Jenkins' url. I believe the url is generally http://[your jenkins url]/bitbucket-hook/
Make the trigger a repo push.
In your Jenkins job, check the box "Build when a change is pushed to BitBucket" under the Build Triggers section.
Now any time you commit to the repo you created the Webhook on, that Jenkins job will be run.
You can also limit what branches trigger commits by parameterizing your Jenkins build to ignore certain branches / keywords / etc if that's something you need for your specific project.
You can use webhooks to trigger build automatically. There are few options how to use it. See the following articles: this, this and this.

Triggerig Jenkins pipeline job after code pushed to github

I want to know how we can setup a jenkins pipeline job which gets triggered after each commit made github private repository.
I am able to do it using a freestyle job but not able to do it using a pipeline.
I did setup the gihub project url, GitHub hook trigger for GITScm polling and wrote a simple pipeline script of checking out the branch.
When I do a changes in the branch and commit it the build wont get triggered.
Can I get a solution on this please?
It works when we add a timestamp block in the pipeline code.
I m able to trigger the pipeline by Adding a GitHub Webhook in Jenkins Pipeline.
I have followed steps mentioned in this blog.
In my case jenkins is running on localhost. Replacing localhost with your jenkins_url should work.
Also, I did not found GitHub Pull Requests mentioned in the blog, so I skipped that step.
After completing the configuration you have to build the pipeline manually once, after that everytime a developer commits a code to GitHub, pipeline build will be triggered.

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!

Resources