Bitbucket webhook returning 401 from TeamCity
I'm trying to setup a webhook on bitbucket that forces a build and subsequently runs unit tests every time a PR is submitted. The request is made on the bitbucket side just fine (I can check the "View Requests" section and the calls are being made). However,
it's returning a 401 with each call, with the message in the body saying:
> Authentication Required
> To login manually go to "/login.html" page

To setup the webhook I've done the following:
- Whitelisted the bitbucket IPs as suggested on [this][2] page (outbound IPv4 column only)
- Connected bitbucket to TeamCity using the following steps:
1. Go to specific build > Edit Project Settings > Connections > Add Connection
2. Select Connection Type == Bitbucket Cloud & copy URL (not "Callback URL")
3. Go to Bitbucket > Settings > Add Webhook & paste the URL (not "Callback URL") from step 2 in the URL textbox
4. Select Triggers: Choose from a full list of triggers > Pull Request > Created
5. Went to my account > Bitbucket settings > OAuth > Add OAuth consumer
6. Added URL/Callback URL from step 2
7. Under permissions checked every "Read" box I could see (just trying to get this working)
8. Copied the Key/Secret in the TeamCity form from Step 2 (still open in another browser)
I'm able to log into the URL from Step 2 on my desktop and manually trigger a build. Also TeamCity can successfully poll bitbucket and kick off builds after a PR has been merged. Can anyone who's succesfully set this up let me know what, if anything, I'm missing?
Please sign in to leave a comment.
Hi Neal,
I've been going through the configuration, and initially seems correct, but the OAuth authentication only gets so far. Where are the 401s happening? When TeamCity is trying to pull data or when Bitbucket is trying to push the hook event into teamcity to trigger a build?
Also please consider this thread: https://community.atlassian.com/t5/Bitbucket-questions/Trigger-teamcity-build-on-pull-request/qaq-p/601076It looks like at least a few months back, bitbucket cloud support recommended to go directly through vcs triggers and polling instead of webhooks.
Hi Denis,
From what I can tell the 401 occurs when Bitbucket is trying to push the hook event into teamcity. I've opened fiddler on the VM and don't see any notification that a request is being sent in from bit.
If that's when the 401 happens, then it looks like bitbucket is failing to authenticate with teamcity, so the OAuth doesn't really have anyhing to do there. I'd suggest checking with BitBucket to see whether you are missing something, maybe during the time since that comment they finally managed to make webhooks work.
I have similar problem: 401 + "
"
I have the same problem ... but it works ! Have realized yesterday that it goes to pending state on TC server and then I had to change VCS configuration to trigger the build on commit and ... voila !