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

1
10 comments

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)

0
Avatar
Permanently deleted user

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.

  1. I browse to the Connections tab in TeamCity for the Root project.
  2. I click on Add Connection and select Bitbucket Cloud from the Connection type drop down.
  3. I'm provided with some OAuth consumer details for my TeamCity instance (URL: <team-city-instance-url>, Callback URL: <team-city-instance-url>/oauth/bitbucket/)
  4. I also get a couple of inputs on the modal for adding the consumer Key and Secret
  5. I login to Bitbucket
  6. I go to the Team I'd like to setup OAuth access for.
  7. I browse to Settings and then OAuth
  8. I click on Add consumer
  9. I fill in the required fields including the URL and Callback URL that was provided by TeamCity and I provide Read Permissions for Account, Team membership, Projects, and Repositories.
  10. After clicking Save, I receive the Key and the Secret.
  11. I go back to TeamCity and add in the Key and the Secret and Click Save
  12. I the browse to VCS Root in TeamCity and click on Create new VCS Root
  13. I click on the bitbucket icon after which a modal appears "To show available repositories TeamCity requires access to your Bitbucket Cloud account" with the option to "Sign in to Bitbucket"
  14. After clicking the Sign in to Bitbucket  button, I receive that error I mentioned in my original post.

Could this be related to the method I'm hosting TeamCity? It's currently being hosted in IIS using a Reverse Proxy.

0
Avatar
Permanently deleted user

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= ....

0

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.

0

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"

0
Avatar
Permanently deleted user

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?

0
Avatar
Permanently deleted user

@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.

0
Avatar
Permanently deleted user

@Sasan - that is unfortunate. But thanks for letting me know!

0

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.

0

@Robsender I fixed BitBucket integration by adding following outbound rule

<outboundRules>
    <rule name="Fix BitBucket redirect">
        <match serverVariable="RESPONSE_LOCATION" pattern="^https://[^/]+/site/oauth2/(.*)" />
        <conditions>
            <add input="{RESPONSE_STATUS}" pattern="^302" />
        </conditions>
        <action type="Rewrite" value="http://bitbucket.org/site/oauth2/{R:1}" />
    </rule>
</outboundRules>

 

0

Please sign in to leave a comment.