Remote Trigger Bamboo build from BitBucket webhook?
Asked by iamkenos:

I'm new to bamboo and webhooks. I'm trying to start a bamboo build automatically when a PR to master branch from my repo is opened.

I followed [this guide](https://confluence.atlassian.com/bamkb/how-to-trigger-a-bamboo-build-from-bitbucket-cloud-using-a-webhook-872271665.html) but the remote trigger is not starting at all.

**Bamboo:**

![bamboo-1.png](/t5/image/serverpage/image-id/33303i7E6879039FD71E09/image-size/large?v=v2&px=999 "bamboo-1.png")

**BitBucket:**

![bamboo-2.png](/t5/image/serverpage/image-id/33304i170895B7DB85E131/image-size/large?v=v2&px=999 "bamboo-2.png")

I've already checked the following:

- verify that the whitelisted ip is correct (the bitbucket webhook fails if i remove that)

- my bamboo plan is enabled and is building fine on manual run

Bamboo plan in YAML:

```
---
oid: 7818389690603565060
key: XT
name: XXX - TEMP
project:
 oid: 7819374853022025730
 key: DIGQA
repositories:
- oid: 7818811903068661169
 parentRepository: 7818811903068661168
triggers:
- name: Bitbucket Server repository triggered
 description: ''
 pluginKey: com.atlassian.bamboo.plugins.stash.atlassian-bamboo-plugin-stash:stashTrigger
 enabled: true
 configuration: {}
 triggerConditions:
 com.atlassian.bamboo.triggercondition.internal:plansGreenCondition:
 enabled: 'false'
 triggeringRepositories:
 - 7818811903068661169
- name: Remote trigger
 description: Master PR Trigger
 pluginKey: com.atlassian.bamboo.triggers.atlassian-bamboo-triggers:remote
 enabled: true
 configuration:
 repository.change.trigger.triggerIpAddress: 10.40.1.120
 triggerConditions:
 com.atlassian.bamboo.triggercondition.internal:plansGreenCondition:
 enabled: 'false'
 triggeringRepositories:
 - 7818811903068661169
branchConfiguration:
 planBranchCreation:
 enabled: false
 removedBranchCleanup:
 enabled: false
 inactiveBranchesCleanup:
 enabled: false
 merging:
 enabled: false
 notificationStrategy: notifyCommitters
 triggers: inherited
 issueLinking: enabled
dependencies:
 configuration:
 enabledForBranches: 'true'
 requireAllStagesPassing: null
 blockingStrategy: none
 childPlans: []
permissions:
 users:
 xxxxxxxx:
 - administration
 - build
 - clone
 - read
 - write
 groups: {}
 roles:
 user:
 - read
 anonymous:
 - read
plugins:
- pluginKey: com.atlassian.bamboo.plugin.system.additionalBuildConfiguration:concurrentBuild
 configuration:
 custom.concurrentBuilds.overrideNumberOfConcurrentBuilds: 'true'
 custom.concurrentBuilds.numberOfConcurrentBuilds: '1'
- pluginKey: com.atlassian.bamboo.plugin.system.additionalBuildConfiguration:buildExpiry
 configuration:
 custom.buildExpiryConfig.enabled: 'false'
- pluginKey: com.atlassian.bamboo.plugin.artifact.handler.local:artifactHandlersConfiguration
 configuration:
 custom.artifactHandlers.useCustomArtifactHandlers: 'false'
buildDefinition:
 custom.predefinedVariables: '{"variableSetList":[]}'
stages:
- oid: 7818530428091950756
 name: Default Stage
 jobs:
 - oid: 7818671165580276746
 key: JOB1
 name: Default Job
 tasks:
 - oid: 7819234115533708305
 description: Checkout Default Repository
 pluginKey: com.atlassian.bamboo.plugins.vcs:task.vcs.checkout
 configuration:
 repositories:
 - ref: defaultRepository
 buildDefinition:
 cleanWorkingDirectory: false
 repositoryDefiningWorkingDirectory: -1
...
```

**===========================================================================**

EDIT 1: {#toc-hId-1844989122}
-----------------------------

Okay, so I realized the hook and the trigger is actually working. I misunderstood the trigger setup on bamboo.

**Current behavior:**

1. PR to master is opened
2. BitBucket webhook (on PR) is fired
3. Bamboo trigger is set to remote / bitbucket server repo. Because of this, the build will not start until the changes are commited / PR is actually merged

**Problem:** I want the build to trigger once the PR is opened (before merge). To a bit more context, this is the ideal flow of my build:

1. Checkout the PR code (revision)
2. Run my tests against the PR revision

I'm looking at the following links as it seems they managed to do it somehow but I can't make sense of the bits of info provided in both the links.

* [bamboo - build my pull request](https://stackoverflow.com/questions/38383953/bamboo-build-my-pull-request/38396250#38396250)
* [What's wrong with bamboo](https://blog.oyanglul.us/make%20bamboo%20support%20github%20pull%20request%20with%20status%20api)


Answers:
author: Foong
body: For the Webhooks in Bitbucket Cloud repository, is the option "Choose from a full list of triggers" selected so that it can be configured to trigger when Pull Request Created?

Since the commit exist in the repository branch, is the branch plan created at *Bamboo Plan Configuration \>\> Branches* so that it can run build with the related repository branch?

comments: author: iamkenos
body: Hi, thanks for your response!

++For the Webhooks in Bitbucket Cloud repository, is the option "Choose from a full list of triggers" selected so that it can be configured to trigger when Pull Request Created?++

-- No, and i dont see that option either. but the Pull Request event is already selected; Meaning, the webhook is fired successfully upon opening a PR

++Since the commit exist in the repository branch, is the branch plan created at *Bamboo Plan Configuration \>\> Branches* so that it can run build with the related repository branch?++

-- Yes. The plan branch is already created.

**Problem:** If I open the PR, the bitbucket webhook is fired, but bamboo will then wait for file changes before the build is started. This means that the build will start ONLY when the PR is merged.

What I want to accomplish is automatically start the build in bamboo once a PR is opened in bitbucket and not wait for the merge to happen. This build is supposed to execute tests and will eventually signal bitbucket on the test results as an indicator whether the PR code is good to merge or not.


author: Foong
body: > No, and i dont see that option either. but the Pull Request event is already selected; Meaning, the webhook is fired successfully upon opening a PR

Just notice the screen shot that it is Bitbucket Server instead of Bitbucket Cloud. For Bitbucket Server, there is no need to create any Webhook. Bitbucket Server will trigger Bamboo by default if Application Link is created between both servers.

From the Bamboo Specs, there is no need to disable Bitbucket Server repository triggered and create Remote trigger. It will work fine with Bitbucket Server repository triggered.
> Yes. The plan branch is already created.

When the branch plan is created in Bamboo, did it run for the first time? Automatic Branch creation can be configured at *Plan Configuration \> Branches* to create branch plan when the PR is created (it will be triggered to build immediately too).
> If I open the PR, the bitbucket webhook is fired, but bamboo will then wait for file changes before the build is started.

Yes, even though the PR is fired, if there is no new commit in the branch, the branch plan will not be triggered. Is there any new commit in the repository branch after the PR is created?


author: iamkenos
body: > Just notice the screen shot that it is Bitbucket Server instead of Bitbucket Cloud. For Bitbucket Server, there is no need to create any Webhook. Bitbucket Server will trigger Bamboo by default if Application Link is created between both servers.
>
> From the Bamboo Specs, there is no need to disable Bitbucket Server repository triggered and create Remote trigger. It will work fine with Bitbucket Server repository triggered.

I used remote trigger as a workaround because I'm getting some sort of proxy issue when I use the bitbucket server trigger (bitbucket webhook request fails upon opening a PR). Will this be an issue with the setup I'm trying to do?
> When the branch plan is created in Bamboo, did it run for the first time? Automatic Branch creation can be configured at *Plan Configuration \> Branches* to create branch plan when the PR is created (it will be triggered to build immediately too).

I created the branch plan manually and tested that it builds fine by running it manually and automatically by merging the PR. The real missing bit is run it when the PR is opened.
> Yes, even though the PR is fired, if there is no new commit in the branch, the branch plan will not be triggered. Is there any new commit in the repository branch after the PR is created?

Yup! I'm testing with actual commits. Would you be able to provide me a step by step guide on how to configure the plan to run on PR open?

Meanwhile, I'll explore the automatic branch plan creation. Thanks!


author: Foong
body: > I used remote trigger as a workaround because I'm getting some sort of proxy issue when I use the bitbucket server trigger (bitbucket webhook request fails upon opening a PR). Will this be an issue with the setup I'm trying to do?

There is no need to use Bitbucket Webhook as well when using Bitbucket Server repository triggered. Bitbucket Server will still trigger Bamboo without the webhook if the Application Link is created.

Perform the following steps to confirm if the Bitbucket Server repository triggered works fine:

1. Enable Bitbucket Server repository triggered
2. Disable Remote trigger
3. Delete the Bitbucket Webhook in Bitbucket Server
4. Select the option **When pull request is created** at *Bamboo Plan Configuration \> Branches \> Create plan branch*
5. Save the setting
6. Create a PR in Bitbucket Server
7. Check Bamboo log file atlassian-bamboo.log for the following message:

```
2018-10-03 21:59:15,983 INFO [http-nio-8085-exec-10] [AuthenticatorImpl] Authenticated app 'Bitbucket:5629199447' as user 'null' successfully
2018-10-03 21:59:15,987 INFO [http-nio-8085-exec-10] [AccessLogFilter] 127.0.0.1 POST http://localhost:8085/rest/remote-event-consumer/latest/events/stash-pullrequest-opened-remote-event 255617kb
2018-10-03 21:59:16,009 INFO [AtlassianEvent::0-BAM::EVENTS:pool-1-thread-11] [PullRequestAwareEventListener] Received pull request opened event [ stash, from: refs/heads/testbranch to: refs/heads/master]
```

> Meanwhile, I'll explore the automatic branch plan creation. Thanks!

If the option **When pull request is created** is selected at *Bamboo Plan Configuration \> Branches \> Create plan branch* , the above trigger event will automatically create a branch plan and build for the first time.


author: iamkenos
body: > Perform the following steps to confirm if the Bitbucket Server repository triggered works fine:

1.
   > Enable Bitbucket Server repository triggered
2.
   > Disable Remote trigger
3.
   > Delete the Bitbucket Webhook in Bitbucket Server
4.
   > Select the option **When pull request is created** at *Bamboo Plan Configuration \> Branches \> Create plan branch*
5.
   > Save the setting
6.
   > Create a PR in Bitbucket Server
7.
   > Check Bamboo log file atlassian-bamboo.log for the following message:

Hi, I don't see the "When pull request is created" at the create plan branch screen.

This is the bamboo version we're using:

**Version** 5.14.3.1

**Build number** 51416

**Build date** 12/5/16

Also, I confirmed that the link between bitbucket and bamboo is already configured.

Is there anything I'm missing?

Thanks!![1.png](https://community.atlassian.com/t5/image/serverpage/image-id/34046i569C9BA52BB439B5/image-size/large?v=v2&px=999 "1.png")

![2.png](https://community.atlassian.com/t5/image/serverpage/image-id/34047iF59AA7A6568F8008/image-size/large?v=v2&px=999 "2.png")


author: Foong
body: > **Version** 5.14.3.1

Its a new feature in Bamboo 6.0+

[Bamboo 6.0 Release Notes](https://confluence.atlassian.com/bamboo/bamboo-6-0-release-notes-894743804.html)

Based on your use case, Bamboo need to be upgraded to 6.0+ so that it can be configured with this new feature.


author: iamkenos
body: I see. Thanks for the info! If you can suggest any workaround for this use case without a Bamboo upgrade that will be highly appreciated! :)


Tags: webhook