• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
No results for ""


Bitbucket Pipes

Read time: 1 minute
Last edited: Dec 06, 2021
Code references is an Enterprise feature

Code references is available to customers on an Enterprise plan. To learn more, read about our pricing. To upgrade your plan, contact Sales.


This topic explains how to use the ld-find-code-refs utility with Bitbucket Pipes to create code references in LaunchDarkly.

You can use the ld-find-code-refs utility with Bitbucket Pipelines to automatically populate code references in LaunchDarkly. To do this, you must create a Pipes configuration using LaunchDarkly's code reference pipe.


To set up Bitbucket Pipes, you must have the following prerequisite:

  • A Bitbucket Pipelines configuration file. To create one, navigate to the Pipelines section of your Bitbucket repository.
  • An API access token with writer permissions. To learn more, read API access tokens.
API tokens can also use custom roles

Alternatively, you can give the access token access to a custom role with the code-reference-repository resource specifier. To learn more, read Custom roles.

Setting up the Pipes configuration

To set up the Bitbucket Pipes configuration:

  1. Create a new Pipeline configuration in your Bitbucket repository.
  2. Configure the Pipeline to run on push using the default configuration. Include the following variables:
  • LD_ACCESS_TOKEN: This secured variable should be your API access token.
  • LD_PROJ_KEY: This should be your LaunchDarkly project key. Find it in Account settings > Projects.

Here's an example of a minimal Pipeline configuration:

An example Pipeline configuration.
An example Pipeline configuration.

You can copy and paste the following code into a blank Pipelines configuration if you have set the LD_PROJ_KEY and LD_ACCESS_TOKEN environment variables as repository variables:

2 default:
3 - step:
4 script:
5 - pipe: launchdarkly/ld-find-code-refs-pipe:2.4.0
6 environment:

To learn more about repository variables, read Atlassian's documentation.

  1. Confirm that the pipeline is working by creating a new pull request with the workflow file and visiting the Pipelines page on your repository's webpage. If your pipeline fails, there may be a problem with your configuration. To investigate, check the pipeline's logs to view any error messages.

Pipeline configuration

The code reference pipe may be configured with additional environment variables to enable more functionality.

This table explains the additional variables:

LD_ACCESS_TOKENA LaunchDarkly access token with writer-level access, or access to the code-references custom role resource.
Supply this as a secured environment variable.
LD_PROJ_KEYA LaunchDarkly project key. Find it in **Account settings > Projects**.Yes
LD_REPO_NAMESets the repository name for this project. This is useful if you have a single monorepo containing multiple YAML configurations, each of which maps to its own LD_PROJ_KEY. Each YAML configuration must have a unique LD_PROJ_KEY and LD_REPO_NAME combination so it displays correctly in the LaunchDarkly dashboard. Defaults to the current Bitbucket repository.No
LD_CONTEXT_LINESThe number of context lines above and below a code reference for the flag parser to send to LaunchDarkly.
If < 0, no source code is sent to LaunchDarkly.
If 0, only the lines containing flag references are sent.
If > 0, sends that number of context lines above and below the flag reference.
A maximum of 5 context lines may be provided. Defaults to 2.
LD_BASE_URISet the base URL of the LaunchDarkly server for this configuration. Defaults to https://app.launchdarkly.com.No
LD_DEBUGEnables verbose default logging. Defaults to false.No
LD_IGNORE_SERVICE_ERRORSIf enabled, the scanner terminates with exit code 0 when the LaunchDarkly API is unreachable or returns an unexpected response. Defaults to false.No
LD_LOOKBACKSets the number of Git commits to search in history for whether a feature flag was removed from code. Set this to 0 to disable it. Setting this option to a high value will increase search time. Defaults to 10.No