Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page provides information regarding setting up your Jenkins instance to use SSH credentials for communication with Bitbucket. This workflow is applicable when using the Git plugin.

Generate SSH key pair

Before configuring Bitbucket and Jenkins, you must first generate the SSH key each will use. There are many different options for generating an SSH key and you can use whichever method meets the requirements set by your organization. This example generates an SSH key using ed25519 on the Terminal application in macOS. The example key does not use a passphrase and saves to the default location.

  1. Open Finder > Applications > Utilities > Terminal. The Terminal window opens.

  2. Enter ssh-keygen -t ed25519 at the command prompt and press ENTER.

  3. Press ENTER to save the key to the default location.

  4. Press ENTER to not include a passphrase and again to confirm.
    The SSH key pair is created and saved to the directory.

  5. Copy the key to the clipboard with the pbcopy < ~/.ssh/id_ed25519.pub command. With the key copied to the clipboard, you can quickly and easily paste the key to Bitbucket and Jenkins. If you are using a different key type (RSA, ECDSA), substitute ed25519 with the alternative key type.

Info

You are currently in Webhook to Jenkins for Bitbucket Cloud documentation. Click Server/Data Center to move to that document.

Aura inline button
summaryServer/Data Center
paramsJTdCJTIybGFiZWwlMjIlM0ElMjJTZXJ2ZXIlMkZEYXRhJTIwQ2VudGVyJTIyJTJDJTIyc2l6ZSUyMiUzQSUyMm1lZGl1bSUyMiUyQyUyMnNoYXBlJTIyJTNBJTIyY2lyY3VsYXIlMjIlMkMlMjJzdGF0ZXMlMjIlM0ElN0IlMjJpZGxlJTIyJTNBJTdCJTIyY29sb3JzJTIyJTNBJTdCJTIyYmFja2dyb3VuZCUyMiUzQSUyMiUyM2Y5NmMyYyUyMiUyQyUyMmxhYmVsJTIyJTNBJTIyJTIzZmZmZmZmJTIyJTdEJTdEJTJDJTIyaG92ZXIlMjIlM0ElN0IlMjJjb2xvcnMlMjIlM0ElN0IlMjJiYWNrZ3JvdW5kJTIyJTNBJTIyJTIzZmZmZmZmJTIyJTJDJTIyb3V0bGluZSUyMiUzQSUyMiUyM2Y5NmMyYyUyMiUyQyUyMmxhYmVsJTIyJTNBJTIyJTIzZjk2YzJjJTIyJTdEJTdEJTdEJTJDJTIyaWNvbiUyMiUzQSU3QiUyMnBvc2l0aW9uJTIyJTNBJTIybGVmdCUyMiUyQyUyMmljb24lMjIlM0ElMjJmYS1zZXJ2ZXIlMjIlN0QlMkMlMjJsaW5rJTIyJTNBJTdCJTIydmFsdWUlMjIlM0ElMjIyNjQzNzI5OTMlMjIlMkMlMjJ0eXBlJTIyJTNBJTIycGFnZSUyMiU3RCU3RA==

In this section

Table of Contents
minLevel1
maxLevel7
  1. Click your profile avatar and select Personal Settings. Your Personal Settings page opens.

  2. From the side menu, select SSH keys.

  3. Click Add Key to open the Add SSH keys dialog.

  4. Add a Label to help in managing multiple SSH keys and paste your SSH key in the Key field.

  5. Click Add Key.

Jenkins configuration

  1. Log into your Jenkins instance.

  2. Add or select the job you want to associate with your Bitbucket repository.

  3. Once you are in the job, click Configure from the left menu.

  4. Select the Source Code Management tab and the Git option when the Configuration page opens.

  5. In the Repository URL field, enter the URL for the Bitbucket repository you want Jenkins to integrate with.

  6. Click Add to open the Jenkins Credentials Provider dialog.

  7. Select SSH Username with private key from the Kind pulldown list.

  8. Provide the following information:

    • Scope - Leave this at the default Global credentials setting.

    • ID (optional) - Set this to help better identify this specific configuration. If left blank, Jenkins generates an ID.

    • Description (optional) - Add a description to help differentiate between credentials.

    • Username - Use the same email address as the one used to log into Bitbucket.

    • Treat username as secret (optional)- masks the username in the build log.

    • Enter directly - Select this option. When the Key field appears, click Add and enter the SSH private key.

    • Passphrase - If you included a passphrase when you generated the SSH key, add the passphrase here; otherwise, leave blank.

  9. Scroll to the bottom of the page and click Save.

Info

While you’re in the Source Code Management section, scroll down to Build Triggers and confirm the Poll SCM option is selected. This option is required when using Webhook to Jenkins.

Git host key verification

Once you have finished adding the SSH key information to Bitbucket and Jenkins, you may still encounter an error similar to:

No RSA host key is known

This is a result of how Jenkins verifies the SSH keys presented by the Git repository host servers. By default, the Git plugin uses the Known hosts file method to verify keys. If the host server is not in the file, the key is not verified and Jenkins returns an error message.

One option is to go to Manage Jenkins > Configure Global Security and scroll down until you reach Git Host Key Verification Configuration. Under the Host Key Verification Strategy, switch from Known hosts file to Accept first connection.

With this option selected, Jenkins remembers the first host key encountered for each git server and requires that the same key for future access.