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

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.

Related

Jenkins not triggering build on PR merged in bitbucket

We are using Bitbucket cloud to host our repos and Jenkins for CI/CD.
I have setup a multibranch pipeline which has develop and release branches. I want to trigger develop branch whenever a PR is merged from the feature branches to develop a branch (In fact on any manual webhook edit).
Below are the cases I tried:
Setup Manage hook in Jenkin:
This creates a webhook in bitbucket and when PR is merged, build is triggered.
But when I disable the Repository Push option in the webhook, the build is not triggering on PR merge.
Setup the webhook manually:
In this case, the Jenkins logs show the branch name as PR-XY since not triggering the develop branch.
I have set up a regex to filter branches (only develop and release are allowed) and when I add regex like PR(.*) then build gets triggers from the PR section (not desired case).
I want the build to be triggered from the develop branch, not as the PR branch. I have followed most of the options available in the forums but it's not working. Any help regarding this will be appreciated.
I faced the same issue, it's look like most of jenkins plugins like bitbucket plugin does not trigger the pipeline on merge only. even though i set the bitbucket trigger options like this:
unless you add a check mark next to push option.
to solve this i used another Jenkins plugin called Bitbucket Push and Pull Request
just make sure to uninstall Bitbucket plugin if you have it.
so you can use this one as they mentioned in there docs.
and follow the setup instructions.
note: i only test it with normal pipeline job

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 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.

Showing user details that has triggered the build on Jenkins Server while code is checked in into gitlab

I want to show user details of user who has triggered build on jenkns. I have integrated gitlab and jenkins and gitlab triggers the build on jenkins via web hook. We log in to gitlab through LDAP. Is there any way to show user details got from gitlab on Jenkins ???? Thanks in advance
At the moment, I don't believe this is possible. But it could be implemented.
In most cases where Jenkins jobs are triggered via Git webhook, the job itself is not triggered directly, but rather Jenkins is informed that for a given Git URI, there may have been changes.
Jenkins then polls Git for changes and, if something new was found, triggers a build of the jobs that use that repository. So at this point, various jobs just start, without receiving any special information about the webhook push that happened.
Also, a new build could have been triggered by multiple commits, from several different people, so it may not make sense to show a single person's name as being the one that triggered a build.
However, there are special implementations that understand the webhook payload format of different hosting services (e.g. GitHub, Bitbucket etc.).
Indeed, the GitLab Hook plugin looks like it does this: if you start a build via the /gitlab/build_now webhook endpoint, then on the build page, you'll see why the build started, e.g. "triggered by merge request feature -> develop" or "triggered by push on branch develop with 2 commits".
While it seems that part of the plugin does read an author's name from the payload (presumably for merge requests), this isn't currently shown on the build page.
So you could try implementing this or filing a feature request on the Jenkins plugin.
As a short term workaround, you can also look at the "Changes" page for each build. There you can see which commits were in that build, and the author names should be shown next to each one.
You may have to configure the "repository browser" under the Git section in the job configuration for this to work.

Resources