New access key is required but could not be added to Bitbucket Server

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Server and Data Center Only - This article only applies to Atlassian products on the server and data center platforms.

Problem

Adding a Bitbucket Server repository to Bamboo fails. The following appears in the atlassian-bamboo.log

2016-02-15 17:42:58,262 INFO [http-nio-8085-exec-18] [StashRepository] Public key was added to Bitbucket Server (Bamboo user: admin, application: Bitbucket [http://bitbucket.url], location: repository PROJECT/reponame): ssh-rsa xxx... http://bamboo.url
2016-02-15 17:42:58,709 WARN [sshd-SshClient[ffd7a43]-nio2-thread-3] [AcceptAllServerKeyVerifier] Server at bitbucket.urk/xxx.xxx.xxx.xxx:22 presented unverified EC key: xx:xx:xx...
2016-02-15 17:42:58,803 WARN [Connection killer] [SshProxyCommand] While connecting to [git@bitbucket.url/xxx.xxx.xxx.xxx:22]: Authenticating remote session failed
2016-02-15 17:42:58,920 INFO [http-nio-8085-exec-18] [StashRepository] Can't authenticate with Bitbucket Server despite successful public key storage: ssh-rsa xxx... http://bamboo.url

OR

2016-06-23 13:28:40,541 INFO [ajp-apr-9002-exec-12] [StashRepository] Public key was added to Bitbucket Server (Bamboo user: admin, application: Bitbucket [http://bitbucket.url], location: repository PROJECT/reponame): ssh-rsa xxx... http://bamboo.url
2016-06-23 13:28:40,551 INFO [ajp-apr-9002-exec-12] [GitCommandProcessor] Command was canceled: command /usr/bin/git version failed with code -1. Working directory was [\].

Diagnosis

Under normal conditions, and if performed by a user with repository admin privileges (either via Administration > Global Permissions or explicitly under Project Settings > Permissions or Repository Settings > Permissions), adding a Bitbucket Server repository from within Bamboo automatically creates and adds an Access Key into the Bitbucket Server repository and subsequently performs a Git SSH test against the SSH URL of the repository. From the log above, the Access Key is successfully created and added to Bitbucket Server however, the test fails.

  1. Perform a telnet test from Bamboo to the Bitbucket Server SSH Base URL to confirm connectivity.

    $ telnet bitbucket.ssh.base.url 7999
    Trying 192.168.56.102...
    Connected to bitbucket.host.
    Escape character is '^]'.
    SSH-2.0-SSHD-UNKNOWN


    1. Check the Bitbucket Server SSH access settings at Administration > Settings > Server settings. The SSH port value must be appended to the SSH base URL otherwise, the default value, 22, will be used which requires an additional port forwarding configuration to be setup via a (reverse) proxy. For example, the following setup shows that the port is set to 7999 but since the SSH base URL is  ssh://bitbucket.url , this means that using SSH, the repositories can only be reached on port 22 and implies that you've also set up a proxy.

  2. Confirm that a git client is installed on the machine hosting Bamboo and that if defined, that the path to the git executable configured at Bamboo Administration > Build Resources > Server Capabilities is correct.

Cause

  1. SSH connection cannot be established between Bamboo and to the Bitbucket Server SSH base URL. Common issues:
    1. SSH access is not enabled on Bitbucket Server
    2. The proxy or load balancer listening at the Bitbucket Server SSH base URL does not redirect TCP traffic from port 22 (default port if no port is added to the SSH base URL) to the SSH port defined in Bitbucket Server.
    3. The Bitbucket Server SSH base URL is incorrect.
    4. Firewall blocking access between Bamboo and the Bitbucket Server SSH Base URL.
  2. Incorrect Git executable path is configured in Bamboo.
  3. Incorrect custom Git SSH executable path is configured in Bamboo.

Resolution

  1. Investigate and resolve any network or firewall issues that may be blocking the SSH connection between Bamboo and to the Bitbucket Server SSH base URL.
    1. Configure SSH access in Bitbucket Server: Enabling SSH Access to Git Repositories in Bitbucket Server
    2. Configure the proxy or load balancer to redirect TCP traffic from port 22 to the defined SSH port or append the SSH port to the SSH base URL in Bitbucket Server.
    3. Correct the SSH base URL in Bitbucket Server so that Bamboo attempts connections to the right address.
    4. Add firewall exceptions for the SSH connection between Bamboo and Bitbucket Server.
  2. Make sure that the correct Git executable path is configured at  Bamboo Administration > Build Resources > Server Capabilities.
  3. Most environments do not require a custom Git SSH executable path to be defined and will work if it's removed entirely. However, if it is required, make sure that the correct Git SSH executable path is configured at Bamboo Administration > Build Resources > Server Capabilities

    The default value that is set for the SSH executable is system.git.executable.ssh, which is not a valid executable on any system. If an SSH capability is required, please be sure to replace this default.


Description

Adding a Bitbucket Server repository to Bamboo fails with a "Public key was added to Bitbucket Server" error. This page addresses the steps needed to resolve the issue.

ProductBitbucket
Last modified on Oct 12, 2018

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.