Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins access private BitBucket repo over SSH

I'm having trouble getting Jenkins to clone a git repository on BitBucket via SSH. It's failing with the following message:

Building in workspace /var/lib/jenkins/workspace/test
[ssh-agent] Using credentials git ([email protected]:<user>/<repo>.git)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent]   Java/JNR ssh-agent
[ssh-agent] Started.
Checkout:test / /var/lib/jenkins/workspace/test - hudson.remoting.LocalChannel@2b619bca
Using strategy: Default
Fetching changes from 1 remote Git repository
Fetching upstream changes from origin
ERROR: Problem fetching from origin / origin - could be unavailable. Continuing anyway
hudson.plugins.git.GitException: Command "git fetch -t origin +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: ssh: connect to host bitbucket.org port 22: Connection refused
fatal: The remote end hung up unexpectedly

Steps taken

  • Create an SSH keypair
  • Add the public key as a deployment key for the repository on BitBucket
  • Install the SSH key and username (have tried both 'git' and my BB account name) in the Jenkins Credentials manager plugin
  • Attempt to clone the repository in the build using a URL in form of

    [email protected]:<user>/<repo>.git

I've also tried not using the credentials manager and manually installing the keys in /var/log/jenkins/.ssh/, but to no avail.

Any ideas what I'm doing wrong?

like image 470
user2424511 Avatar asked Sep 18 '13 09:09

user2424511


1 Answers

As @user1562655 suggested out, the clone was failing due to another issue -- in this case the firewall was blocking outgoing ssh on port 22.

The fix was to use port 443 (as the server allows this), and a different BitBucket URL:

ssh://[email protected]:443/<user>/<repo>.git

…instead of

ssh://[email protected]:<user>/<repo>.git

More info on the scheme is available here:

UsetheSSHprotocolwithBitbucket-SSHonPort443

like image 160
user2424511 Avatar answered Feb 18 '23 22:02

user2424511