We're trying out Stash in a POC mode. One of the ideal behaviors for us would be if Stash could trigger a build when a pull request comes in. This way we know the build is good.
So what I've done is setup stash notifier in Jenkins, and told Jenkins to look at the branches refs/pull-requests/*/merge (which should have the merge result, if I understand correctly). Yes I understand this is internal use only, and I understand that it cannot be modfied (I have no inteion of modifying it). I've also setup the Jenkins webhook. When I send the pull request, i don't think the webhook is triggering. Maybe it's not intended to, I'm not sure.
So, is there an alternate solution to this?
Unfortunately, building from the pull request refs is not as straightforward as it may seem.
When you view a pull request in Stash, Stash shows the diff between the 'from' branch of the pull request and the merge of the 'from' branch and the 'to' branch. This merge needs to be recalculated every time someone pushes to either the 'from' or 'to' branch.
For performance reasons, these calculations are done asynchronously on background threads, which means that the refs under /refs/pull-requests are updated some time after push has completed. Therefore, when the webhook sends a notification to Jenkins, the refs under /refs/pull-requests will not have been updated yet.
If you do want to build the pull requests and you're happy building the 'from' branch of a pull request, you could:
Write a post-receive hook that:
Note that such a hook only builds a pull request if the hook is enabled in the 'from' repository for that pull request. So say you have a pull request from a personal fork to the main repository, that pull request would only be built if you enable the hook in your personal fork as well.
Is this still the case where Pull Requests don't work from forked repos? Is there any way besides polling to get this to work?
It literally makes 0 sense to create a Jenkins job for a fork. The public repo's job should have all the builds in it, not only does this come out of the box with GitHub like @Chris Ferry said, it comes seamlessly out of the box with every other product besides BitBucket. Very frustrating.
There is a plugin in Atlassian Marketplace now that you may want to have a look at:
To trigger a build.
Then you can use Stash Notifier plugin to report back to Stash. Use the variable $PULL_REQUEST_FROM_HASH in configuration for Stash Notifier plugin to get it nicely reported in the pull request view =)
I solved it with 2 jobs in Jenkins. One that polls Stash REST API and one parameterized build that does the actual verification. The polling job will trigger the build job with any new pull request. The build job uses Stash Notifier Plugin to report back to Stash.
I wrote a post about it here: http://bjurr.se/building-atlassian-stash-pull-requests-in-jenkins/
Alternatively, what you can do is have a job/plan that builds on every branch that matches a given pattern. Every time a developer pushes a branch to, say, feature/abc or bugfix/xyz the build will trigger. Quite often these branches will correspond to a pull request anyway.
I didn't ask the question, but I am trying to do the same thing. My refspec is
and my branch is the commit's hash (grabbed from a build parameter that I named TAG, so the exact entry I have in branch is $TAG). I'm successfully able to build a pull request by making an HTTP call to http://myjenkinsserver/job/my_job/buildWithParameters?token=TOKEN_NAME&TAG=a4745b5.
I just don't know how to get Stash to trigger Jenkins on a pull request, as John asked. I'm about to write my own hook that hits the URL above.
You may have a look at this blog post where I describe the detailed steps how to setup Jenkins and Stash to trigger automatically the correct Jenkins build(s) when a pull request is created or updated.
I have a very specific issues with Pull Request builds. I am using TeamCity and Bitbucket server and am able to get builds working fine. But problem is if I am building the 'from' branch (refs/pull-requests/*/from) the status is showing up on the PR page on Bitbucket. if I build the 'merge' branch (refs/pull-requests/*/merge), nothing shows up on the PR page.
Badges are a great way to show off community activity, whether you’re a newbie or a Champion.Learn more
After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs