Enabling Jenkins on Ubuntu to ssh to Bitbucket

On your workstation use

$ ssh-keygen

to generate a private-public keypair.

In your Bitbucket account Settings -> GENERAL -> Access keys add a key for Jenkins and copy content of a public one in it.

On your Jenkins machine, sign in as jenkins user and do:

$ nano ~/.ssh/id_jenkins_rsa

and copy content of a private key in there. Then:

$ nano .bash_profile

and copy there following:

[ -z "$SSH_AUTH_SOCK" ] && eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_jenkins_rsa

Save and exit. Make sure you have right permissions:

$ chmod 755 .bash_profile

Logout and log back in. Check if it works:

$ ssh -T git@bitbucket.org

Should authenticate you via a deploy key. Then jenkins can use it like:

$ git clone git@bitbucket.org:youraccount/yourrepo.git

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: