Comment on page
The functionality of Release's LaunchDarkly integration and how to set it up
Release's LaunchDarkly integration allows you to have a pristine, isolated LaunchDarkly environment to use for testing.
Sharing feature flags between multiple environments can cause testing and reliability issues. Release solves this problem by creating a new LaunchDarkly environment each time you deploy a new Release environment and storing the SDK key, mobile key, and client key as environment variables your application can access.
Release handles creating and deleting LaunchDarkly environments with little configuration needed.
Navigate to the Integrations tab for your account.
Each field in the set-up form is required. Except for the Access Token field, you can use the defaults provided.
- Project Key: This is the key for the project you want your environments created under. The default value is
default, as LaunchDarkly always has a project with the key
- Access Token: This is the token for the account you would like to create environments under in LaunchDarkly. You can create or find the access token under Account Settings -> Authorization. All access tokens start with
- Environment Variables: The remaining fields define the names of the environment variables Release will use to store the various API keys from LaunchDarkly. You can change these names to anything you like. Keys are stored as encrypted K8s secrets.
You will need the LaunchDarkly access token to set up your SDK client so that you can choose variations of flags in your application.
Once you have saved these configurations, Release will attempt to use your access token to connect to your LaunchDarkly account. If that works, the integration is ready to go! If not, you'll see errors and can correct any mistakes you have made.
The integration consists of two parts, both of which are automated and handled by Release.
- Pre-deployment step: The LaunchDarkly integration will add a task to each of your deployments to create the feature flag environment.
- Pre-delete step: When you delete an environment, a step will be injected that cleans up by deleting the environment in LaunchDarkly.
The pre-deployment step will create an environment in LaunchDarkly the first time you deploy a space or new configuration.
The environment variables you specified during set up will be populated and exposed to your containers via K8s secrets.
You can then use these environment variables in your code to access your feature flags as you normally would.
The pre-delete step is invoked when a Release environment is removed, whether manually through the UI or when a pull request is merged or closed. The LaunchDarkly integration will remove the corresponding LaunchDarkly environment automatically when the Release environment is removed.
Below are some examples of how to consume the environment variables to use the LaunchDarkly integration.
#Uncomment this section if you would like to use the LaunchDarklyApi gem (https://github.com/launchdarkly/api-client-ruby).
#This is NOT the gem for using the Ruby LaunchDarkly SDK (https://github.com/launchdarkly/ruby-server-sdk).
#Most people do not need to use the LaunchDarkly Rest API defined here: https://apidocs.launchdarkly.com/reference, but
#instead just want to use the SDK to interact with the feature flags in their specific environment.
#If you would like to use the LaunchDarkly Rest API, make sure to install the gem besides uncommenting these lines.
access_token = ENV['LAUNCHDARKLY_ACCESS_TOKEN']
LaunchDarklyApi.configure do |config|
config.api_key['Authorization'] = access_token
config.debugging = true
##To use the LaunchDarkly Ruby SDK, you will need the specific SDK key.
##In this example, I'm setting up `LDClient` under the `Rails.configuration` so it's accessible anywhere
##in your Rails project.
Example of using the
LDClientyou defined above in your Rails application