How to Configure Jenkins Job to Use Bitbucket Repository Access Key

bitbucketJenkinsssh

In one of my bitbucket repositories on a Bitbucket server instance, I've configured an Access Key and would like to use this access key within a Jenkins Job to clone said repository. However, there doesn't seem to be a credential provider for this scenario.

I can't use the username with SSH key since with the access key associated with a system, doesn't have a username.

Can somebody point me in the right direction?

Thx

Best Answer

Just ignore the username; add your access key as an SSH key credential in Jenkins and put whatever you want in the username field. When you clone a Bitbucket repository using SSH keys you almost always use git as the username anyway.

For instance, here is an example Pipeline that will check out a repo using an access key with the ID myAccessKey:

git(credentialsId: 'myAccessKey', url: 'ssh://git@bitbucket.my.org:7999/project/repo.git')

As you should be able to see, it doesn't matter what you put for the username field in your Jenkins SSH credential, because you checkout the repo as the git user regardless.

Alternatively, put git for the username when creating your credential.