Create a Feature Flag
Feature Flags allow you to toggle features in your code on or off, which allows you to progressively roll out features to particular users or groups. By using Feature Flags, you can manage continuous delivery and control who sees which features and when.
This topic describes how to create a Feature Flag in the Harness platform.
A Feature Flag is available only for the project the flag is created in, so you’ll need to create any relevant flags you want to use in each project you want to use them for.
You can use the same flags across multiple environments within a single project, but the flag status in each environment is independent.
Before you begin
Before you create a Feature Flag, you must have completed the prerequisites, that is:
- Created a project
- Created an environment
- Created an SDK key
How Feature Flag variations work
When you create a Feature Flag, you also create different options to label the logic of that flag. These are called flag variations. For example, a simple boolean flag has only two variations, true
and false
.
There are two different types of Feature Flags you can create:
-
Boolean: Has only two variations; true and false.
-
Multivariate: Has multiple variations, you can add as many custom variations as you like.
Create a boolean flag
-
In Feature Flags, click + New Flag.
-
Select Boolean.
-
In About the Flag, in Name, enter a name for your flag and click Next.
infoWhen you name a flag, Harness automatically generates its identifier. You can edit the identifier when you are creating the flag, but not after it is saved. If you rename the flag, the identifier remains the same. For more information, go to Entity Identifier Reference.
-
To make the Feature Flag permanent, select the This is a permanent flag checkbox. Permanent flags are flags you intend to stay in your system indefinitely, so we will never mark them as potentially stale.
-
Click Next.
-
In Variation settings, in Flag Type, select Boolean.
-
In the Name fields, enter the name for the true and false variations, for example, True and False.
-
In Default rules for the flag, select which variation of the flag to serve when the flag is ON or OFF, for example, True when the flag is ON and False when the flag is OFF.
-
Click Save and Close. The Feature Flag is created and is set to OFF by default.
After you have created your Boolean flag, you can:
Create a multivariate flag
Multivariate Feature Flags allow you to serve a different variation of a flag to multiple user groups at one time. For example, a multivariate flag could have the following variations:
- Variation 1 set to OFF
- Variation 2 set to ON
- Variation 3 set to be served only when a user has a certain email address
There is no limit to the number of variations that you can add to a multivariate flag, and you can use strings, numbers, or JSON to define the different Variants.
To create a multivariate flag:
-
In Feature Flags, click + New Flag.
-
Select Multivariate.
-
In About the Flag, in Name, enter a name for your flag and click Next.
infoWhen you name a flag, Harness automatically generates its identifier. You can edit the identifier when you are creating the flag, but not after it is saved. If you rename the flag, the identifier remains the same. For more information, go to Entity Identifier Reference.
-
To make the Feature Flag permanent, select the This is a permanent flag checkbox. Permanent flags are flags you intend to stay in your system indefinitely, so we will never mark them as potentially stale. For example, if you are offering a premium feature to some of your customers but not others, you can use a permanent flag to manage who sees this feature indefinitely.
-
In Variation settings, in Flag Type, select Multivariate and then select the Data Type. You can select, String, JSON, or Number.
-
Enter a Name and Value for each variation you want to use.
-
In Default rules for the flag, define which variation you will see by default when the flag is ON or OFF.
After you have created your multivariate flag, you can then: