Failed to trigger pipeline Jenkins build from Bitbucket - jenkins

I am trying to integrate Jenkins with Bitbucket. For this thing, i have installed on the Jenkins the Bitbucket plugin. In the Bitbucket, i have defined a WebHook. Now i want when a new commit is made in a branch, the Jenkins job to be automatically triggered. But this thing is not working, even if the webhook seems to work and the response is 200.
My webhook:
Jenkins configuration:

Related

Jenkins does not run the building process after a push

I have the following initial situation:
I have a Docker container running Jenkins 2.379
This Jenkins has the Bitbucket Server Integration and the Bitbucket Branch Sourch Plugin installed
The connection to the Bitbucket server seems to work
I also set up a multibranch pipeline that listens to the repository in the connected Bitbucket server instance
And I have set the Scan Multibranch Pipeline Trigger to All pushes.
Finally, it seems that Jenkins has correctly implemented the webhook in the corresponding Bitbucket project.
Changes to some configurations of the multibranch pipeline trigger the scan process, which works properly. If there are changes in the code of the corresponding branch during a push, the build is triggered.
Clicking the "Scan Multibranch Pipeline Now" button has the same result.
But if I just push some code changes into a branch, nothing happens. My pipeline does not start automatically and no build process is started with the changes made.
Goal: Every push a developer does in a branch of this project should trigger the scan for new branches in Jenkis and the build process for new branches or those where something has changed.
I have found the problem/solution. As I said, my Jenkins runs in a Docker container and is hosted locally on my PC (localhost:8080).
Through the credentials, the path from Jenkins into Bitbucket worked and so did creating the webhook. However, for this webhook, the Bitbucket server plugin entered its address (localhost:8080). So now when a push into a Bitbucket repo happens, this webhook was triggered on Bitbucket's localhost:8080 (so presumably Bitbucket itself and not Jenkins).
The solution was now quite simple. I used a tool called ngrok to make my localhost:8080 (on which Jenkins runs) accessible via a URL from the internet.
I then only had to store this URL in Jenkis in system configurations and adapt the webhook in my Bitbucket repository.

Jenkins multibranch pipeline does not detect pull requests in Bitbucket server

I am having trouble getting Jenkins multibranch pipeline detect pull requests created in the Bitbucket server (private instance). I have setup the "Bitbucket server webhook to Jenkins" which is triggering the build on master, develop and feature branches except pull-requests. I have defined the build steps in Jenkisfile and can confirm the PR branch also includes the Jenkinsfile.
In the Jenkins configuration, I have enabled "Discover branches" under Branch Sources configuration
Pull Request isn’t a branch, it is usually something that is done prior to publishing to a branch. Usually, the pull request is approved, then published to the master branch.
Ok. After multiple trial and error and google search, I have managed to get the Jenkins Multibranch pipeline work with Bitbucket server. The key was to use 'Bitbucket' (from bitbucket branch source plugin) as the Branch source. Also, I had to include a dummy trigger in my Jenkinsfile for the Jenkins webhook to work from bitbucket
triggers {
bitbucketPush()
pollSCM('0 0 1 1 0')
}

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 can I get Jenkins builds to report failures back to Bitbucket server?

My work is running Jenkins and Bitbucket Server (so instead of the bitbucket cloud, they host their own bitbucket version). I am used to having passing/failing builds on github and bitbucket cloud immediately reporting back on PRs and branches as to whether the build passed or failed. I want to give that gift to my team in the current environment. How do I get PRs in Bitbucket server to receive success/failure of builds from Jenkins?
[Figure 1 just shows an example of the functionality I want, operational on PRs in github+codeship]
While the Webhook to Jenkins for Bitbucket can help notify Jenkins to poll whenever there is a commit, you still need to be mindful of the “lazy ref updates” in Bitbucket (described in this thread)
We had to implement something that would do a get to the REST API for the pull-request/*/changes before the call to the Jenkins /git/notifyCommit url.
The last Jenkins URL /git/notifyCommit comes from the Jenkins Git plugin.
See more at "Configuring Webhook To Jenkins for Bitbucket".
Once Jenkins is properly called, you can then, as mentioned in "Notify build status from Jenkins to Bitbucket Server", use the "Jenkins Stash Pullrequest Builder", from nemccarthy/stash-pullrequest-builder-plugin.
The bitbucket server has build-status API. It stores a build-status for particular commit, there is no separate PR build status. The PR build status is a build status of the head commit in this PR.
You can implement yourself the rest api call to update the build status or to use one of the existing plugins. We use Post Webhooks for Bitbucket bitbucket plugin in conjunction with Bitbucket Branch Source jenkins plugin.
You could you use BitBucket REST API to achieve this ?
Here the how-to update commits with the build status :
Updating build status for commits
Commit status are then shown in Pull Request and on branches
you can setup Stash notifier plugin , it workds perfectly with BitBucket and notifies build status to branch and pull request

Jenkins Multibranch Pipeline Gitlab WebHook

I am trying to setup a multibranch build pipeline that will build each branch with a Jenkinsfile everytime a push occurs. I have set everything up, but the issue is that it works with only one branch. I saw a github thread that you need to use the url generated from gitlab plugins build trigger for the GitLab Webhook:
Build when a change is pushed to Gitlab. GitLab CI Service URL: http://...
I used this but this is provides auto-triggering for only the branch I found it in.
How do I change this so that it builds this for all my branchs?

Resources