LaunchDarkly Developer Documentation

Get started in under 30 minutes.
LaunchDarkly provides feature flags as a service for Java · Python · Ruby · Go · Node.js · PHP · .NET. Control feature launches -- who sees what and when -- without multiple code deploys. Easy dashboard for phased rollouts, targeting and segmenting.
Need more help? write us at support@launchdarkly.com

Get Started    Documentation

GitHub Actions

Beta

GitHub Actions is currently in open beta. If you haven't signed up already, you may sign up here. If you're waiting for access to the Github Actions beta, and would still like to set up Code references, please see the other available configuration methods

The ld-find-code-refs utility can be used with GitHub Actions to automatically populate code references in LaunchDarkly.

Once you've created a LaunchDarkly access token, store the newly created access token as a repository secret titled LD_ACCESS_TOKEN. Under Settings > Secrets in your GitHub repo, you'll see a link to "Add a new secret". Click that and paste in your access token and click "Save secret".

GitHub secret configuration

GitHub secret configuration

Next, create a new Actions workflow in your selected GitHub repository. If you don't already have a workflow file, you'll need to create a new file titled main.workflow in the .github directory of your repository. Under "Edit new file", paste the following code:

workflow "Find flag references" {
  on = "push"
  resolves = ["find_flags"]
}
action "find_flags" {
  secrets = [
    "LD_ACCESS_TOKEN",
  ]
  env = {
    LD_PROJ_KEY = "$YOUR_PROJECT_KEY"
  }
  uses = "docker://launchdarkly/ld-find-code-refs-github-action:1.0.0"
}

If you already have a main.workflow file, copy and paste the above to the bottom of your main.workflow file. If you wish to verify that you've pasted the above correctly, you can go into the visual editor and ensure that there are no syntax errors.

Commit this file under a new branch. Submit as a PR to your code reviewers to be merged into your master branch. You do not need to have this branch merged into the master for code references to appear in the LaunchDarkly UI for your flags; code references will appear for this newly created branch.

As shown in the above example, the workflow should run on the push event, and contain an action which uses docker://launchdarkly/ld-find-code-refs-github-action as its action provider. The LD_ACCESS_TOKEN configured in the previous step should be included as a secret, as well as a new environment variable containing your LaunchDarkly project key.

Once your workflow has been created, the best way to confirm that the workflow is executing correctly is to create a new pull request with the workflow file and verify that the newly created action succeeds.

If the action fails, there may be a problem with your configuration. To investigate, dig into the action's logs to view any error messages.

GitHub Action running

GitHub Action running

GitHub Action succeeded

GitHub Action succeeded

Additional configuration options

ld-find-code-refs may be configured with additional environment variables to enable more functionality.

Variable
Description
Required

LD_ACCESS_TOKEN

A LaunchDarkly personal access token with writer-level access, or access to the code-reference-repository custom role resource. Should be supplied as a GitHub repository secret.

yes

LD_PROJ_KEY

A LaunchDarkly project key. The flag finder will search this project for code references in this project.

yes

LD_EXCLUDE

A regular expression (PCRE) defining the files and directories which the flag finder should exclude. Partial matches are allowed. Examples: vendor/, vendor/.*

no

LD_CONTEXT_LINES

The number of context lines above and below a code reference for the flag finder to send to LaunchDarkly.

If < 0, no source code will be sent to LaunchDarkly.

If 0, only the lines containing flag references will be sent.

If > 0, will send that number of context lines above and below the flag reference.

A maximum of 5 context lines may be provided. Defaults to 2

no

LD_BASE_URI

Set the base URL of the LaunchDarkly server for this configuration. Defaults to https://app.launchdarkly.com

no

LD_DEBUG

Enables verbose default logging. Defaults to false

no

LD_DELIMITERS

Specifies additional delimiters used to match flag keys. Must be a non-control ASCII character. If more than one character is provided in delimiters, each character will be treated as a separate delimiter. Will only match flag keys with surrounded by any of the specified delimeters. This option may also be specified multiple times for multiple delimiters. By default, only flags delimited by single-quotes, double-quotes, and backticks will be matched. Default: [" ']`.

no

Here's an example of a workflow configured to exclude the vendor directory and send 1 line of context above and below each code reference for each flag in the "default" project:

workflow "Find flag references" {
  on = "push"
  resolves = ["find_flags"]
}
action "find_flags" {
  secrets = [
    "LD_ACCESS_TOKEN",
  ]
  env = {
    LD_PROJ_KEY = "$YOUR_PROJECT_KEY"
    LD_EXCLUDE = "vendor/"
    LD_CONTEXT_LINES = "1"
  }
  uses = "docker://launchdarkly/ld-find-code-refs-github-action:1.0.0"
}

GitHub Actions


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.