Bitbucket Cloud Integration with TeamCity
After updating TeamCity from 9.1.6 to 2017.1.1, attempting to setup a cloud connection with Bitbucket using the Connections feature in TeamCity fails. To be more precise, the Connection is added using the Bitbucket provided key and secret and the bitbucket icons appear throughout the TeamCity web app. However, clicking any of the icons and then clicking on the subsequent "Sign in to Bitbucket" button produces a 404 error as shown below. The TeamCity instance is installed on a Windows Server 2012 and is hosted using a reverse proxy in IIS. Any help is appreciated.
HTTP Status 404 - /site/oauth2/authorize
type Status report
message /site/oauth2/authorize
description The requested resource is not available.
Apache Tomcat/7.0.68
Please sign in to leave a comment.
Hi Sasan,
the error is obviously that the url is wrong, but the question would be... where does that URL come from? That's not the URL provided by teamcity for oauth with bitbucket. Make sure you provided the right URL when setting up the bitbucket oauth connection (it's <site>/oauth/bitbucket)
Hi Denis,
Thanks for the reply. I'm not quite sure what you mean by that question. So here's a little more detail on the problem.
Could this be related to the method I'm hosting TeamCity? It's currently being hosted in IIS using a Reverse Proxy.
Also,
The error mentioned in step 14 above is shown in a popup that has a URL such as the one below (minus some of the oauth details)
<team-city-instance-url>/site/oauth2/authorize?client_id= ....
Hi Sasan,
Thanks for the detailed explanation, and sorry for my rather ambiguous question. It was a 404 error so the URL was obviously wrong, and I had gone around through the BitBucket process and couldn't find it, so I asked where it was coming from. I've been further trying to replicate the issue, without much success, though, although I've managed to find out where the <address>/site/oauth2/authorize address comes from. Please keep in mind that I'm running my tests in 2017.1.1. While the basic auth procedure worked since the beginning, there might be situations where this might have helped.
When making the request, site/oauth2/authorize is part of the URL to the bitbucket server, contacted during the OAuth. It would seem that your IIS is actually bouncing back the request to the teamcity server instead of forwarding it to the BitBucket side of things. Unfortunately, I cannot be of much help here, as IIS reverse proxies aren't really encouraged from our side, they are usually tricky to fully configure, but definitely can confirm that path should be requested from the bitbucket server, not teamcity, in case that might be of help figuring out how to configure it.
I had the same issue with an IIS reverse proxy. The solution is to disable host rewrite:
1. IIS -> Server Farms -> TeamCity
2. Open Proxy settings
3. Disable "Reverse rewrite host in response headers"
Did anyone even find a solution to this? I have exactly the same problem using TeamCity Professional 2018.2.2 (build 61245) with an IIS on Windows Server 2016 set as a reverse proxy on top (using URL Rewrite).
@Arni - I'm not using a Server Farm, just a regular IIS "Site" as a reverse proxy.
@Denis - if you are saying that TeamCity is directing the user to a URL on TeamCity instead of BitBucket.org, that is not a reverse proxy problem. All a reverse proxy does is say: "If a request comes to teamcity.example.com, I'll hand it off to localhost:8080" or whatever. It can't hijack a different domain. So - is this a bug in TeamCity?
@Sasan - did you ever find a solution to this?
@Robseder, Unfortunately, I was not able to fix the original issue at the time. Instead of using the Bitbucket integration tools, we decided to use the generic git repository integration tools in TeamCity.
@Sasan - that is unfortunate. But thanks for letting me know!
I have same similar issue when trying to configure BitBucket as authentication module.
I'm getting redirected to TeamCity url, rather than to BitBucket.org for login page.
Login works fine, if I manually replace host name in this url to bitbucket.org
P.S. I'm not using any reverse proxy configuration, just hosting as a simple IIS web site.
@Robsender I fixed BitBucket integration by adding following outbound rule