Skip to main content

Configure an agent with Bitbucket Data Center access

In order to view recipe results and commit changes from a recipe back to Bitbucket, you'll need to create an application link in Bitbucket and configure the Moderne agent with the appropriate variables.

To assist with that, this guide will:

Prerequisites

  • You will need administrator access to your Bitbucket on-premise instance

Bitbucket configuration

Step 1: Generate a public and private key for Bitbucket

This key will be used by the Moderne agent to talk to Bitbucket.

openssl genrsa -out bitbucket_privatekey.pem 1024
openssl req -newkey rsa:1024 -x509 -key bitbucket_privatekey.pem -out bitbucket_publickey.cer -days 365
openssl pkcs8 -topk8 -nocrypt -in bitbucket_privatekey.pem -out bitbucket_privatekey.pcks8
openssl x509 -pubkey -noout -in bitbucket_publickey.cer > bitbucket_publickey.pem
  1. Go to the Administration page in your Bitbucket instance

  2. Select Application Links from the System section

  3. Click on "Create link"

  4. Ensure that the Application Type is set to Atlassian product (this looks weird, but this is the documented path for external applications to integrate)

  5. Enter the URL for your Moderne instances as the Application URL:

    Create link

  6. Click Continue

  7. Define a new Incoming Application with the following settings:

    FieldValue
    Application NameModerne
    Application TypeGeneric Application
    Service Provider Namemoderne
    Consumer keyOauthKey
    Request token URLhttps://your-domain.moderne.io
    Access token URLhttps://your-domain.moderne.io
    Authorize URLhttps://your-domain.moderne.io
    Create incoming link
  8. Click Continue

  9. Complete the Incoming Link configuration:

    FieldValue
    Consumer KeyOauthKey
    Consumer NameModerne
    Public KeyPaste the public key (bitbucket_publickey.pem) from step 1
  10. Click Continue to complete the Application Link creation

Agent configuration

Step 3: Configure the Bitbucket private key for the Moderne agent

In order for the Moderne agent to work with your Bitbucket instance, it will need to be provided with the private key you generated in Step 1. Before Moderne can use this key, though, you will need to convert it to a single-line string.

If you're using Bash or another shell, you can obtain the single-line string by copying the results of the following command (for use in Step 4):

cat bitbucket_privatekey.pcks8 | sed '1d;$d' | tr -d '\n'

If you're not using a shell, please follow these instructions instead:

  1. Open up the bitbucket_privatekey.pcks8 key in a text editor
  2. Remove the first and last line (header and footer) of the private key
    • The first line should be: -----BEGIN PRIVATE KEY-----
    • The last line should be: -----END PRIVATE KEY-----
  3. Remove all newline and return characters
  4. Copy the contents of the file as a single-line string. This will be used in Step 4

Step 4: Configure the Moderne Agent

The following table contains all of the variables/arguments you need to add to your Moderne agent run command in order for it to work with your Bitbucket instance. Please note that these variables/arguments must be combined with ones found in other steps in the Configuring the Moderne agent guide.

info

You can configure multiple Bitbucket instances by including multiple entries, each with a different {index}.

Variables:

Variable NameRequiredDefaultDescription
MODERNE_AGENT_BITBUCKET_{index}_PRIVATEKEYtrueThe private key you configured for this Bitbucket instance.
MODERNE_AGENT_BITBUCKET_{index}_URLtrueThe fully-qualified URL of the running Bitbucket instance. For example: https://bitbucket.myorg.com.
MODERNE_AGENT_BITBUCKET_{index}_ALTERNATEURLS_{index}falseThe list of alternative fully-qualified URL of the running Bitbucket instance. For example: https://bitbucket.myorg.com.
MODERNE_AGENT_BITBUCKET_{index}_SKIPSSLfalsefalseSpecifies whether or not to skip SSL validation for HTTP connections to this Bitbucket instance. This must be set to true if you use a self-signed SSL/TLS certificate.
MODERNE_AGENT_BITBUCKET_{index}_SSH_PRIVATEKEYfalseThe SSH private key used to establish a SSH connection with Bitbucket.
MODERNE_AGENT_BITBUCKET_{index}_SSH_PASSPHRASEtrue (If the SSH private key is specified)The file name of the private key, which the agent will store locally.
MODERNE_AGENT_BITBUCKET_{index}_SSH_SSHFILENAMEtrue (If the SSH private key is specified)The file name of the private key, which the agent will store locally.
MODERNE_AGENT_BITBUCKET_{index}_SSH_USERtrue (If the SSH private key is specified)The username used for SSH communication with Bitbucket.
MODERNE_AGENT_BITBUCKET_{index}_SSH_PORTtrue (If the SSH private key is specified)7999The port used to communicate via SSH with Bitbucket.

Example:

docker run \
# ... Existing variables
-e MODERNE_AGENT_BITBUCKET_0_PRIVATEKEY=yourPrivateKey \
-e MODERNE_AGENT_BITBUCKET_0_URL=https://bitbucket.myorg.com \
# ... Additional variables