During our daily development, the architecture group receives a fair number of pull requests. Ideally, as part of the review process on these pull requests, we would check out the code locally and run all the tests to ensure that the commit doesn't break the build. In reality, that's way too time consuming and we just go on blind faith that the developer in charge of the modification has already ensured all the tests pass. As you can guess, that's not always the case.
What I'm wondering is, would it be possible for you to implement a process that kicks off a Jenkins job to test the pull requests before the code is merged into master? That way, the architecture team could know at a glance if the PR passed all the tests, and it would save us all time in reviewing something that may not be working.
This is going to be a long answer, but I am hoping we can help one another here.
You can currently see the status of your Pull Request before merging it using the UI when you're integrating with Bamboo. Please have a look at:
Currently Bamboo has an option so it will build a branch every time a change is pushed to that branch/repo
You can read more about this on:
When you create a plan that uses a linked Stash repository, with Stash 3.1 and later, Bamboo uses the 'Stash repository triggers the build when changes are committed' trigger option by default.
Because of this integration with Bamboo allied with the concept of "Plan Branches" in the tool (link above), when Build builds/notifies Stash about the build result of the PR's "origin branch", this is an example of how a PR looks like in Stash:
The image above means that 3 different systems built the "origin branch" of that PR successfully and that'd be ok to merge it back into master.
I told you the Bamboo story to come back to your question which is now: how to do I accomplish the same results with Jenkins?
In order to notify Jenkins so it will start building the Stash repo after changes are pushed, there is a plugin in Marketplace that could help you:
The link to its documentation can also be found there:
with these plugins (you need one in Stash and another one in Jenkins itself as per the documentation above) you will be able to set this up as well for Jenkins (notify Jenkins that is time to build because changes have been pushed to a repo and get the build result displayed by Stash).
Once I had a question from a customer about "how to build a specific branch using Jenkins".
My knowledge of the tool is inexistent (sorry about that). However, after searching I answered this customer that this concept doesn't appear to exist and customers are applying the workaround described here:
On the other hand, the same customer came back to me saying:
So I am working with the plugin [Stash Webhooks to Jenkins], and I figured out that you can have it build a certain branch by specifying which branch you want to build in the Git step of the Jenkins job.
I honestly don't know which one of the above is correct or more appropriate – I know that's what you need to accomplish. In theory, if you can make Jenkins build the "origin branch" of the PR and notify Stash about its result, you should get the same screen I showed you for Bamboo for the PR with its result.
I am hoping this answer helps you and that you're able to enlighten the community with your findings about Jenkins.
Let us know how you go! :smile:
Thanks for the info. I did install the following plugins:
STASH: Stash Webhook to Jenkins
Jenkins: Stash Notifier Plugin
I am able to have Jenkins notify STASH via a checkmark the status of a build. The only thing, I can’t get working with the ‘Stash Webhook’ plugin is to build (trigger) a job on a pull request. I think it is some configuration on Stash’s Refspec and Build Branch.
Do you have any ideas on that?
Here is what I see on the STASH server:
Which Refspec do I use and what is the Syntax??
My branch is NOT 'origin master'. It is 'origin newbranch'
Sorry, I don't understand you here.
I am able to have Jenkins notify STASH via a checkmark the status of a build. The only thing, I can’t get working with the ‘Stash Webhook’ plugin is to build (trigger) a job on a pull request.
However, does what I posted answer your question? Meaning: I understood your initial question was that you wanted to see the status of the Pull Request build on Stash.
As I explained above, you have to get your Jenkins to build the "source branch" of the Pull Request and notify Stash about its status. That's what you mean by "building the Pull Request".
I don't know how you can make Jenkins build the "source branch" of the Pull Request. You can look at the references I gave you to figure it out.
you can check out my blog post (https://christiangalsterer.wordpress.com/2015/04/23/continuous-integration-for-pull-requests-with-jenkins-and-stash/) which has a detailed description how to trigger Jenkins jobs on various pull request events and automatically merges the source branch of the pull request with the target branch of the pull request.
Thanks for this Christian, it was super helpful and i've now extended the process you gave to put static code comments on a pull request
It usses another of Thomas Bjerre plugins.
Check out (https://dengelonsoftware.blogspot.co.uk/2017/07/jenkins-bitbucket-and-static-analysis.html) for details
Thanks so much for the blog post. Just one last thing...what steps should I omit (from your blog post) if I only want to execute the Jenkins job based on the pull request but NOT merge my changes after the build passes? I still want to control when to merge my changes. I only want Jenkins to perform a build based on a pull request 'event'.
Hello Community, I’m Anton Genkin, a product manager on the Bitbucket Server and Data Center team and am excited to share that Bitbucket Server 7.0 is now available! It's a platform release, one th...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events