Bitbucket pull request builder plugin keeps triggering same commit build - jenkins

I need to integrate Bitbucket with Jenkins. So that whenever a PR is opened it will trigger a build in Jenkins. Then commit status of the last commit in the PR will be updated as failed or success and this commit wont trigger the build again. (This works beautiful with Github but seems to be a nightmare for me with Bitbucket)
So far I did:
Installed Bitbucket pull request builder plugin.
Set everything up like its described in https://github.com/jenkinsci/bitbucket-pullrequest-builder-plugin#readme
User has write permissions to the repository (we added shh pub key to organization and its in the group that has write permissions)
Problems
Build is triggered over and over again for the same PR/commit
Commit status is not updated on bitbucket
Let me know if I can provide more information.

In my case, the Jenkins URL was set to http://jenkins:8080 and when such a URL was sent to BitBucket via their API, BitBucket returned the error "Invalid URL" (Look in Jenkins Logs: http://yourjenkins:8080/log/all) Which is not handled by the BitBucket Pull Request Builder plugin and thus kept continuously rebuilding all of our pull requests because it thought that build was not in progress. After setting Jenkins URL to http://jenkins.domain.tld:8080/ or http:///jenkins, the BitBucket API started accepting the URL and everything started to work.
But in your case it may be possible that some other error is the cause. You can check your Jenkins Error log to see the failure.
See the following issue: Build status notification fails with Enter a valid URL

Related

Bitbucket Server : Merge check - Minimum successful builds not enabling merge even after the condition is satisfied

I have configured Bitbucket Server to work with Jenkins by enabling a Webhook in Bitbucket with the Jenkins URL and the event being - Pull request approved. So I want a build on Jenkins to be triggered when a pull request is approved by the named reviewer.
The Jenkins job is configured to be triggered remotely using a token and that token is specified in the Bitbucket Webhook along with the Jenkins URL. This is working as expected. The Jenkins job is triggered automatically as soon as the pull request is approved by the reviewer.
But, I have also configured a merge check for the project . The merge check is enabled for minimum successful builds and the number of builds to be successful is configured to be 1. So, I expect the merge button to be enabled as the reviewer has approved the pull request and the Jenkins build has run (also success). But unfortunately, the merge button is not enabled even after all this. I also triggered a build manually on the same commit ( was success too ) but with no success on the merge button being enabled. Please help me out. Thanks.
I had the same problem and here are the steps of how I fixed it.
Use Bitbucket and not Git as the source code management. But, Bitbucket seems to be only avaiable when creating a Multibranch Pipeline.
Now, that you use Bitbucket, install plugin Bitbucket Branch Source Plugin
Bitbucket appears to get the result of the build from Bitbucket Branch Source plugin
The plugin requires some configuration, this webpage helped me a lot.
We had the same problem, if in your case you have at least one failed build before the succesfull one, then you will not be able to merge until you push a new code to the PR branch. This answer comes after discussing it with Bitbucket's support team.

Cannot get Jenkins to update GitHub Pull Request with a build status

I am using the Jenkins plugin GitHub Pull Request Builder to run some commands, and then update the status of my Pull Request.
The job is correctly triggering when I update a PR on GitHub, however I cannot get the job to update the status of the build on GitHub.
I have closely replicated the steps outlined in this article: https://medium.com/#mreigen/integrate-jenkins-builds-into-github-pull-requests-33bc053d6210
When I check the System Logs, I see this error: GitHub project property is missing the URL, cannot start ghprb trigger for job
I have entered the URL everywhere I can find to enter it, but so far nothing has worked.
This is my configuraiton for the plugin:
Any help on how to get the job to successfully add a status message to the Pull Request on GitHub would be greatly appreciated!
On the GitHub Pull Request Builder section of the Build Triggers, enabling the checkbox:
Build every pull request automatically without asking enables the Jenkins job to add an update status to GitHub.
You need to enable the github project option and provide your gihub url there.

Bitbucket Pull Request Builder plugin for Jenkins unable to post comments

The Bitbucket Pull Request Builder plugin for Jenkins allows Jenkins build to be triggers when Pull requests are created or commented on in Bitbucket.
This has been working fine for us, but on one particular repo, it has started failing.
The logs show:
WARNING: bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketBuildTrigger.run() failed for hudson.model.FreeStyleProject#2840d594[ci-metadata-app-new]
java.lang.NullPointerException
at bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketRepository.postBuildTagInTTPComment(BitbucketRepository.java:182)
at bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketRepository.isBuildTarget(BitbucketRepository.java:253)
at bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketRepository.getTargetPullRequests(BitbucketRepository.java:94)
at bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketPullRequestsBuilder.run(BitbucketPullRequestsBuilder.java:37)
at bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketBuildTrigger.run(BitbucketBuildTrigger.java:187)
It looks like the plugin can't post a comment to the Bitbucket API
postBuildTagInTTPComment
Which is preventing the build from triggering.
Has anyone seen this issue before? It is only happening for this particular repo.
Eventually cleared it by deleting all the pull requests and adding them back one by one. I think it had something to do with one PR have a target branch that was behind its source branch.

How to notify the build status to bitbucket UI when there is no pull request create and merge?

Am new to Jenkins. I found a plugin to notify the each commit status in bit bucket UI(Bit bucket Cloud Build Status Notifier Plugin) and am very much confused about notifying the build status.
https://wiki.jenkins-ci.org/display/JENKINS/Bitbucket+Cloud+Build+Status+Notifier+Plugin
Am doing commit continuously in development branch and i have registered the oauth credentials as described in above link with Jenkins job. After the Jenkins job run, i could not see the build status in bit bucket cloud UI.
Could anyone please suggest me whether this plugin update the commit status from pull request page to development branch while merge? Or This plugin can pass the direct build status to development branch when commit done and Jenkins job ran.
Thanks in advance!!!
If the plugin is configured properly you should be able to see the build status posted by the plugin in commit history of your development branch within Bitbucket Cloud. The build status is set for a given commit sha1, that means that it doesn't care if it's a pull request or not since the commit sha1 doesn't change.
If the build status is not shown in Bibucket Clould UI, I guess your problem is related to the plugin or Jenkins configuration. Take a look to the Jenkins log file for more information in order to be able to guide you to solve the problem.

How to trigger jenkins build upon bitbucket pull request merged

I looked at all other related questions and answers, didn't find anything solid, hence I'm opening a new question to look for your kind help, I've been working on this the whole day, any help I can get would be highly appreciated.
Here's my environment:
self-hosted jenkins server (Jenkins ver. 1.651.3) with git and bitbucket plugin installed.
https://bitbucket.org (I do not have a self-hosted bitbucket server)
What I want to do: to trigger jenkins build upon pull request got merged from feature branch to master branch.
Different setting combinations which I had tried:
jenkins: 'Build when a change is pushed to BitBucket' checked.
bitbucket: web hooks trigger: 'Repository push' checked.
Result: build was triggered successfully upon commit to master branch, but that's not what I want, but at least I know the communication between my jenkins server and bitbucket is fine.
jenkins: 'Build when a change is pushed to BitBucket' checked.
bitbucket: web hooks trigger: 'Repository push' checked, and Pull Request - 'Merged' checked.
Result: jenkins does not respond to the pull request merged action. I assumed it would work since I had the Pull Requst - 'Merged' checked in the web hooks trigger setting, and I did see the request was sent by bitbucket to my jenkins server, and it got 200 status code back from my jenkins server, but still, nothing happens.
jenkins: 'Build when a change is pushed to BitBucket' checked. And besides that, I installed another plugin called bitbucket-pullrequest-builder-plugin, and configured it according to the instruction.
bitbucket: web hooks trigger: 'Repository push' checked, and Pull Request - 'Merged' checked.
Result: with the help of bitbucket-pullrequest-builder-plugin, the build was indeed triggered upon pull request created. But the jenkins server polls the bitbucket repository constantly, and I didn't find a way to stop that, no way to trigger build ONLY upon merge neither...
I heard there's people says that you'll need to install a post-hook plugin on the bitbucket server in order to do what I want to do, but the thing is I dont host the bitbucket...
Based on some research you can have a few options as of today Nov 12 of 2017:
Use the generic post webhooks plugin that supports pull request trigger. And from jenkins pick it up with the generic webhooks plugin, then maybe do a secondary trigger from jenkins.
Upgrade the bitbucket server and webhooks to jenkins plugin. The server 4.13 does not work well with later webhooks to jenkins plugin. A paid version of the plugin probably is your best choice.
Or try bamboo that comes with the "plan banches" feature.
When you configure GIT - push, commit... etc hooks, be sure to check the JENKINS git selection, and set the BRANCH to check for (** specifies all branches) and most importantly,
USE localtunnel.me or similar to set your JENKINS online or it won't work.

Resources