Trigger bamboo from bitbucket Webhooks
Asked by Hamed Beiranvand:

Hi guys,  

I spent a couple of hours to figure out why I'm not able to trigger a webhook from bitbucket to bamboo, I found nothing yet   

Issue:  
I want to detect when a PR is merged or a branch is deleted which as I see I'm not able to track these need from bamboo, so I need to have a webhook in bitbucket and call a bamboo reset api base on this page  
<https://confluence.atlassian.com/bamboo/triggering-a-bamboo-build-from-bitbucket-cloud-using-webhooks-873949130.html>  

But this solution is now working because each time I got this error message  

```
{"message":"Anonymous user can't access this resource. If it should be available, modify anonymous user permissions at Administration > Security settings","status-code":401}
```

<br />

The only access we have for Anonymous group is view which I see this is not enough to call this API from bitbucket  
<https://confluence.atlassian.com/bamboo/bamboo-permissions-369296034.html>  

<br />

<br />

So I don't know what to do and how to track if a PR is merged or a branch is deleted.  

I would appreciate to tell me what the problem is  

<br />

FYI: bamboo and bitbucket version is the latest one


Answers:
author: Daniel Santos
body: Hi [@Hamed Beiranvand](/t5/user/viewprofilepage/user-id/3322954),

To allow an anonymous user to trigger change detection you need to enable the following security option:

* *Admin \>\> Security settings \>\> \[ \]Allow anonymous users to trigger remote repository change detection and Bamboo Specs detection*

Your instance should be able to get the branch deletion even if there is no webhook configured. Bamboo has a feature for that. The branch detection feature is enabled by default and has the check interval configured in:

* *Admin \>\> General configuration \>\> Branch detection interval*

Let me know if after configuring the security property you get it working.

comments: author: Hamed Beiranvand
body: [@Daniel Santos](/t5/user/viewprofilepage/user-id/502125) Thank you for your reply. I really appreciate it.  

<br />

About anonymous user, I think it's not a good idea in security perspective because it will enable the public to trigger the plan.  

<br />

And about the branch deletion, I do not know the way to trigger a plan when a branch is deleted.  

<br />

let me tell you what I want to do, for each PR a new environment would be created which it's supposed to be deleted when the PR is merged or deleted.  

So I created a new plan for this case, but I need to trigger it when the PR is merged or deleted.  


author: Daniel Santos
body: Hi [@Hamed Beiranvand](/t5/user/viewprofilepage/user-id/3322954)

I'm not sure if I really understood you from the beginning.
> About anonymous user, I think it's not a good idea in security perspective because it will enable the public to trigger the plan.

It would not be free to everyone. Only the IPs configured in the repository trigger will be able to use the resource, but I understand your concern.
>
> And about the branch deletion, I do not know the way to trigger a plan when a branch is deleted.

If I understand you correctly you are trying run a build to check the changes of a pull request, is that correct? I think I didn't get that from the first message.

Have you tried the *Plan configuration \>\> Branches \>\> When pull request* is created configuration?
> let me tell you what I want to do, for each PR a new environment would be created which it's supposed to be deleted when the PR is merged or deleted.
>
> So I created a new plan for this case, but I need to trigger it when the PR is merged or deleted.

Please check that configuration. It should work for what you need.


author: Hamed Beiranvand
body: I already know about this part

> *Plan configuration \>\> Branches \>\> When pull request*

and about

> <br />
>
> It would not be free to everyone. Only the IPs configured in the repository trigger will be able to use the resource

<br />

we do not allow to this solution for security stuff   

<br />

but anyway I really appreciate for your time to spent to answer my question


author: Daniel Santos
body: Hi [@Hamed Beiranvand](/t5/user/viewprofilepage/user-id/3322954)

sorry about the late reply, but I have a question for you.

* Have you tried adding user and password in your request URL in bitbucket webhook?  
  It would be something like:

  ```
  https://<USER>:<PASSWROD>@BAMBOO_URL/rest/triggers/1.0/remote/changeDetection?planKey=PLAN-KEY&skipBranches=false

  ```

I just wanted to make sure you tried this option before giving up.  
Let me know if that is an option to move forward.


author: tuimazy2008
body: Hello [@Daniel Santos](/t5/user/viewprofilepage/user-id/502125) , It seems that I have same issue, I can't trigger bamboo plan using Bitbucket webhook, I tried your last suggestion:

```
/<USER>:<PASSWROD>@BAMBOO_URL
```

But unfortunately it not helped


Tags: bitbucket

webhook