Post Merge build trigger plugin to bamboo

I am using the Atlassian plugin Post-Receive WebHooks to call Bamboo to start a build on all commits. However when a Merge is done, the hook does not trigger.

In searching for an answer I found this question: https://answers.atlassian.com/questions/130202/post-hooks-unsuccessfully-triggered-after-clicking-merge-button-in-a-pull-request

Which there is a reply that explains that a plugin can be created that consumes the PullRequestMergedEvent object, but I have no idea how that would be done. I've found a couple of people discussing the issue, but not one implementation of a plugin to fix this issue.


The other question is the closest I've found to someone putting something together. I attempted myself but can't spend more time on this as it's already taken up days of my research and only let to brick walls.

Anyone have any advice on actual implementation, or even an example not unlike the Post-Receive WebHook plugin that works great, outside of this instance?

3 answers

1 accepted

Had to make a support ticket to try and resolve this.

Hi Chris,

This may be a dumb question, but which hook are you talking about. Unfortunately there are a couple. Are you talking about the one we just uploaded ot Marketplace recently?

That plugin, and most others I hope, should be implementing AsyncPostReceiveRepositoryHook which will listen for both Push and Merge events already. The advice from Tim is old and was before we introduced our new hook API.

Otherwise, is there anything in your $STASH_HOME/log directory that might indicate an error?

Cheers,

Charles

I just had time to start looking into this, thank you so much for the reply. Interesting that it should already be set up though.

I have no confirmed that we are using that plugin, with the Add-on key: com.atlassian.stash.plugin.stash-web-post-receive-hooks-plugin

Could not seem to find the Add-On key to compare on the page you linked, but I would think it a little absurd if they were different Add-ons.

I will investigate further into the logs and see if I can find something in there to report back soon.

So after further testing, it was found that the domain wasn't resolving properly.

However, we are using the "Gitflow Workflow" where you commit a new feature branch, then merge into a "Development" branch, then later merge to master. When doing this, it appears that if we merge to Master, the build is kicked off. However if we merge to development, the build is NOT kicked off?


Is this a known issue, or is there any tips that may fix this behaviour?

Hi Chris,

Honestly I'm not sure, I suspect this may be part of the problem:

https://answers.atlassian.com/questions/150470/why-commits-to-branch-trigger-build-on-master-and-not-branch

My quick reading on the subject I think Bamboo has slightly different Plan keys for branch builds, so a URL containing the main plan key won't trigger them. :(

A quick and dirty option would be to add another URL to the hook which has the plan key of the development branch build. If you need this to work for more than those two branches then this obviously won't scale and I suspect you'll have to enabling polling.

Sorry I can't be more help.

Charles

Charles,

I actually attempted the same thing you suggest earlier, adding another URL to the trigger. I attempted it with the branch build key (Same key but with the number 1 appended as seen in the URL) and Bamboo replies to the request saying that it's successful. However it is appearing that even though there was a merge, Bamboo is not actually detecting any changes.


When I commit a new feature branch, or update one via a commit, everything works properly. It's only when I merge to anything but the MASTER branch, it won't actually trigger anything on Bamboo.

It works perfectly for a merge to MASTER, and on top of that, it will build the Development branch when I merge Development into Master as well!

Hi Chris,

I guess I'd be curious to know whether Bamboo is definitely receiving the hook, or if there's a bug in the Stash hook. You can either look at the Bamboo access logs, or alternatively use something like RequestBin to see if the hook is POSTing on the merge.

http://requestb.in/

Cheers,

Charles

Well I know that the hook is getting sent. I have even attempted sending it by hand (Using Curl to craft the post request in Cygwin), and get the same result. Bamboo is telling me 200 OK Build kicked off, however in the logs of Bamboo I'm seeing:

2013-09-05 10:40:25,067 INFO [4-BAM::PlanExec:pool-7-thread-2] [ChangeDetectionListenerAction] No changes found for 'STP-GFRT1'

Of note, the Master branch is the base plan: STP-GFRT

So I'm more curious why Bamboo would query stash, and NOT see the merge to development? It's almost as if the Git server (Stash) is not showing a changeset for any branch merge except for when the merge is to Master. Or it is putting those merges into a different changeset that Bamboo is not accessing?

Hi Chris,

At this point I'm going to have to phone a friend. Bamboo is not calling any Stash specific APIs, they'll be using Git directly, so it's out of Stash's hands at that point.

Sorry I can't be more help.

Charles

Hi Chris,

A few quick questions. If you try the curl again a minute later I'm assuming the result is still the same? Just want to make sure something isn't being cached.

The other question is if you manually kick off the build does Bamboo report the merge under 'Changes' as normal?

Cheers,

Charles

To elaborate, the merge commit ID I expected on bamboo from Git for when I merged the feature to develop:

Christopher Lefevre
c08b6afM Merge pull request #34 in FEAT/gitflow-experiment from feature-test to develop * commit '9fd85ed62ce9a246b88023f20e6e87e7461cdfda': Updated ChrisFeature 14 mins ago

However instead, I found that bamboo referenced THIS commit, which was a previous commit of a merge to Master from Development:

Christopher Lefevre
6e40354M Merge pull request #33 in FEAT/gitflow-experiment from develop to master * commit '186401eff8bedddb81cf22eef5b044f05212a912': Added text to readme file testing for atlassian 20 mins ago

Couple of new things that I've noticed.

First off, I feel I need to note the version of bamboo we're using. 4.4.1. We're upgrading to 5.1 next Tuesday, as I've now found out that we're not completely up to date.

Secondly, I attempted the Curl statement several times over the course of several minutes. Unfortunately nothing changed.

I ended up doing 2 thorough tests. First I tested commiting a new branch (Feature1), Curl to make the new build, which worked, but was slow. This did not show the commit log for the new branch, as all it said was "Initial Build" and did not include the change log for the commit.

I then merged that branch with the Development branch (Specifically using the Stash UI pull request functionality), and did not delete the new branch. This I tried using the Curl statement 3 times over the course of 5 minutes. No builds were done. I then merged the development branch into the Master branch, and re-ran the Curl statement. This time the Master AND Development branch both kick off new builds. Both showing all commits in their notes.

Next I edited a file within the new branch I had made (Feature1). I commited the edit, then re-ran the Curl statements. This time the branch now showed the new commit log in bamboo properly for that branch when it built. I then merged that branch back into Develop again, and ran the Curl statements again. Again there was no build kicked off.


Finally, I ran a manual build of the Development branch, and noticed the changeset that showed up did NOT look familliar. I looked up the changelog commit ID, and found that instead of being the merge of Feature1 to Develop, it was actually the previous merges commit ID to the Master branch.

Hi Chris,

Firstly, thanks so much for all the information. The behaviour you're seeing (obviously) doesn't sound right.

I hate to do this, but you would you mind raise a support ticket (for Bamboo)? That will be your best and fastest way to get some more help.

Best of luck,

Charles

Thank you for your effort Charls. I'll have to wait until Monday to talk to our IT dept. about our support information and such, and I'll be sure to create a ticket then. Also still need to update to the latest version as well.

Hi Chris,

I have a question pertaining to setting up the webhook plug-in.

What did you put as your URL for bamboo?

I see that we are supposed to include the path to the hook listener, but I'm not sure how to locate the hook listener for bamboo.

It would be great if you could let me know how to find the hook listener address.

Thank you,

Perron

You ned to set up your bamboo plan to react to repository changes, not polling. Then you need to use the REST API for triggering the build via the url:

http://<IP of your Bamboo Instance>:<Port>/api/rest/updateAndBuild.action?buildKey=<Build Key>

The build key can be found by looking at the URL of the plan you wish to trigger. For example mine ends with the URL: browse/STP-GFRT

STP-GFRT being the Build Key that we use.

For example, our internal version is:

http://192.168.254.10:8080/bamboo/api/rest/updateAndBuild.action?buildKey=STP-GFRT

Of note, we have the server set up to be at port 8080 and /bamboo

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,494 views 0 5
Read article

Atlassian User Groups

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!

Find my local user group

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

Groups near you