Skip to main content

Remote Feature Flag Cleanup Templates

Last updated on

Remote Feature Flag Cleanup templates help you identify and remove stale feature flagsA feature flag is a conditional toggle in Harness FME that enables or disables specific functionality without deploying new code. It allows for controlled feature rollouts, A/B testing, and quick rollbacks if issues arise. from your codebase. These remote templates automate feature flag cleanup by generating pull requests (PRs) with the proposed code changes. The templates are maintained in the Harness Community GitHub repository.

TypeUse case
PipelineUse when you want automated discovery, flag selection, and cleanup generation.
StageUse when you already know which feature flag should be removed and only need the cleanup workflow.

Each execution generates a single pull request for a single feature flag cleanup.

Import a template

The following templates are available for use in your Harness pipelines.

TemplatePath
Pipeline (Harness Code)fme/templates/Pipeline/Feature_Flag_Cleanup/v1.yaml
Pipeline (GitHub)fme/templates/Pipeline/Feature_Flag_Cleanup_Github/v1.yaml
Stage (Harness Code)fme/templates/Stage/Feature_Flag_Cleanup/v1.yaml
Stage (GitHub)fme/templates/Stage/Feature_Flag_Cleanup_Github/v1.yaml

To import a remote template:

  1. From the Harness FME navigation menu, navigate to Project Settings > Templates.
  2. Click New Template.
  3. Select either Pipeline or Stage depending on the template type you want to import.
  4. Enter a name for the template.
  5. Optionally, include a description and any tags for the template.
  6. Add a version label for the template.
  7. Optionally, upload a logo for the template.
  8. Select where you'd like to save the template to: Project, Organization, or Account.
  9. Select Remote under How do you want to set up your template?.
  10. Select Third-party Git provider and specify a Git connector, repository, Git branch, and the YAML path.
  11. Click Start.
  12. Save the template and reference it in your Harness pipeline.

Required inputs

The following runtime inputs are required when configuring the remote templates:

Pipeline Template (Harness Code)
InputDescription
HARNESS_API_TOKENAPI token used to access the Harness Code repository.
REPO_NAMEName of the repository that contains the feature flag code references.
FME_ADMIN_APIKEYFME Admin API key used to retrieve feature flag metadata.
FME_PROJECT_IDFME project identifier used during discovery.
FEATURE_FLAG_SELECTION_CRITERIANatural-language criteria used to identify cleanup candidates.
LLM_AUTH_TOKENAuthentication token used by the cleanup code agent.
Pipeline Template (GitHub)
InputDescription
REPO_URLURL of the GitHub repository that contains the feature flag code references.
REPO_BRANCHRepository branch used as the base branch for cleanup changes.
REPO_API_TOKENAPI token used to authenticate with GitHub.
REPO_USERNAMEGitHub username associated with the API token.
FME_ADMIN_APIKEYFME Admin API key used to retrieve feature flag metadata.
FME_PROJECT_IDFME project identifier used during discovery.
FEATURE_FLAG_SELECTION_CRITERIANatural-language criteria used to identify cleanup candidates.
LLM_AUTH_TOKENAuthentication token used by the cleanup code agent.
Stage Template (Harness Code)
InputDescription
HARNESS_API_TOKENAPI token used to access the Harness Code repository.
REPO_NAMEName of the repository that contains the feature flag code references.
FME_ADMIN_APIKEYFME Admin API key used to retrieve feature flag metadata.
FME_PROJECT_IDFME project identifier associated with the feature flag.
FEATURE_FLAGName of the feature flag to remove.
TREATMENTTreatment value to inline during cleanup (for example: on, off, or variant_a).
REASONExplanation for why the feature flag is safe to remove.
LLM_AUTH_TOKENAuthentication token used by the cleanup code agent.
Stage Template (GitHub)
InputDescription
REPO_URLURL of the GitHub repository that contains the feature flag code references.
REPO_BRANCHRepository branch used as the base branch for cleanup changes.
REPO_API_TOKENAPI token used to authenticate with GitHub.
REPO_USERNAMEGitHub username associated with the API token.
FME_ADMIN_APIKEYFME Admin API key used to retrieve feature flag metadata.
FME_PROJECT_IDFME project identifier associated with the feature flag.
FEATURE_FLAGName of the feature flag to remove.
TREATMENTTreatment value to inline during cleanup (for example: on, off, or variant_a).
REASONExplanation for why the feature flag is safe to remove.
LLM_AUTH_TOKENAuthentication token used by the cleanup code agent.

Selection criteria

FEATURE_FLAG_SELECTION_CRITERIA defines which feature flags should be considered eligible for cleanup.

Write the criteria as a short, explicit sentence describing the desired cleanup conditions. Some examples include:

Flags that are 100% rolled out in production
Flags that are 100% rolled out in all environments
Flags with rollout status 100% released
Flags that are no longer targeted to any segments
Flags with the tag 'ready_for_cleanup'

Use a pipeline template

Use a pipeline templateA reusable end-to-end workflow that discovers eligible feature flags, lets you select a cleanup candidate, and generates a pull request with the proposed code changes. when you want the workflow to discover and suggest cleanup candidates automatically.

  1. Import a pipeline template.
  2. Configure the required runtime inputs.
  3. Run the pipeline.
  4. Select a feature flag from the generated candidate list.
  5. Review and merge the generated pull request.
What happens during the pipeline execution?
  1. The cleanup agent discovers eligible feature flags.

    The pipeline begins by cloning the repository, retrieving feature flag metadata, applying the selection criteria, and generating a list of eligible cleanup candidates.

    Candidate flags are written to a JSON file (typically ff_eligible.json). This file is used to populate the feature flag selection step later in the workflow.

  2. The cleanup agent selects a feature flag.

    After discovery is complete, the pipeline pauses for manual approval.

    The selection dropdown is populated using values from ff_eligible.json. Each option includes the feature flag name, selected treatment, and generated cleanup reason. The selected value is stored as a runtime variable and passed into the cleanup stage.

  3. The cleanup agent opens a pull request.

    The cleanup stage clones the repository, constructs a cleanup prompt using the selected inputs, applies code changes locally, creates a new branch, commits and pushes the changes, and opens a pull request using the repository provider API.

Cleanup behavior

The cleanup agent attempts to remove feature flag conditionals, inline the selected treatment, and remove unused feature flag references.

Review Generated Pull Requests

The cleanup templates generate proposed code changes automatically. Always review generated pull requests before merging changes into production branches.

For example:

Before Flag Cleanup
if (isEnabled("checkout_flag")) {
newFlow()
} else {
oldFlow()
}
After ('TREATMENT=on')
newFlow()

Each execution generates a new branch, a single commit, and a pull request containing the code changes and the reason for cleanup.

Use a stage template

Stage templates are useful when feature flag cleanup is part of a larger engineering workflow. You can provide the required cleanup inputs directly, including FEATURE_FLAG, TREATMENT, REASON, and more.

Common use cases include removing flags after a rollout reaches 100%, cleaning up flags after an experiment concludes, removing flags during migrations from another feature flag provider, and adding cleanup to scheduled technical debt workflows.

  1. Import a stage template.
  2. Configure the required runtime inputs.
  3. Run the stage.
  4. Review and merge the generated pull request.
What happens during the stage execution?

The cleanup agent opens a pull request.

The cleanup stage clones the repository, constructs a cleanup prompt using the selected inputs, applies code changes locally, creates a new branch, commits and pushes the changes, and opens a pull request using the repository provider API.

Cleanup behavior

The stage template follows the same cleanup workflow used by the pipeline template, but skips feature flag discovery, candidate generation, and manual feature flag selection. Because the feature flag is already identified, the workflow proceeds directly to cleanup and pull request generation.

Each execution generates a new branch, a single commit, and a pull request containing the code changes and the reason for cleanup.