Remove stale LaunchDarkly flags with Azure DevOps pipelines
The scheduled cleanup from the GitHub Actions guide, on Azure DevOps. A weekly pipeline asks LaunchDarkly which flags are stale, removes each from the code with flagrm and an agent, and opens an Azure Repos pull request per flag.
This guide covers the Azure DevOps setup only. What counts as a stale flag, the launchdarkly: config and the local check with flagrm stale are the same as in the GitHub Actions guide. Follow its steps 2 and 3, Configure LaunchDarkly and Try it locally first, before you add the pipeline, so you know which flags it will pick.
1. What the pipeline needs
- flagrm as a dev dependency, so
npm ciinstalls it, and the Claude Code setup fromflagrm initcommitted: theflagrm-removeandflagrm-reviewskills and the Stop hook. - A
launchdarkly:section inflagrm.config.yaml. For flags that have been ON for four weeks and aren’t permanent, that isminDaysOn: 28,temporaryOnly: trueandtags: { exclude: [permanent] }. - A variable group named
flagrm(Pipelines, Library) with two secret variables:LD_API_TOKEN(a LaunchDarkly token with the Reader role is enough) andANTHROPIC_API_KEY. The pipeline must be allowed to use the group. Either add it under the group’s Pipeline permissions, or approve the request on the first run. - Repository permissions for the build service identity. In Project settings, Repositories, select the repository, then Security. Find <project> Build Service (<organization>) and set Contribute, Create branch and Contribute to pull requests to Allow. The pipeline uses this identity’s
System.AccessTokento push the branch and open the pull request.
2. Add the pipeline
flagrm ships the full file as examples/ci/azure-pipelines.yml. Copy it to main under its own name, for example .azure-pipelines/flagrm-stale.yml, so it doesn’t replace the azure-pipelines.yml your CI may already use. Then create a pipeline from it: Pipelines, New pipeline, Azure Repos Git, select the repository, Existing Azure Pipelines YAML file. The pipeline runs in two stages, only on the schedule or when you start it by hand, never on pushes or pull requests.
trigger: none
pr: none
schedules:
- cron: "0 6 * * 1" # Mondays 06:00 UTC
displayName: Weekly flag cleanup
branches:
include: [main]
always: true # run even when nothing changed since last time
pool:
vmImage: ubuntu-latest
variables:
- group: flagrm
always: true matters here. Flags go stale because time passes, not because someone pushed code. Without it, Azure Pipelines skips a scheduled run when nothing has changed since the last successful scheduled run.
3. The first stage picks the flags
stages:
- stage: stale
jobs:
- job: stale
steps:
- checkout: self
persistCredentials: true
- task: NodeTool@0
inputs: { versionSpec: 22.x }
- script: npm ci
- script: npx --no-install flagrm stale --json > "$(Agent.TempDirectory)/stale.json"
displayName: Ask LaunchDarkly which flags are ready
env:
LD_API_TOKEN: $(LD_API_TOKEN)
# ...then build a matrix from the "remove" verdicts
Secret variables aren’t passed to scripts automatically in Azure Pipelines, so each step that needs one lists it under env. If the config is wrong or LaunchDarkly can’t be reached, the step fails and no agent starts.
The last step, named pick, turns the remove verdicts into a job matrix and publishes it as the output variable flags with ##vso[task.setvariable variable=flags;isOutput=true]. It skips any flag whose branch flagrm/remove-<flag> already exists, so an open pull request isn’t duplicated, and any name that isn’t safe to use in a branch name.
The second stage reads that variable through the stage, job and step names (stale, stale and pick). If you rename any of them, update both references in the second stage.
4. The second stage removes each flag
- stage: remove
dependsOn: stale
condition: and(succeeded(), ne(dependencies.stale.outputs['stale.pick.flags'], '{}'))
jobs:
- job: remove
timeoutInMinutes: 120
strategy:
matrix: $[ stageDependencies.stale.stale.outputs['pick.flags'] ]
maxParallel: 2
steps:
# checkout, NodeTool, your build toolchain, npm ci, install Claude Code
- script: claude -p "/flagrm-remove $FLAG" --allowedTools "Bash,Read,Edit,Write,Glob,Grep"
displayName: Remove the flag with Claude Code
env:
ANTHROPIC_API_KEY: $(ANTHROPIC_API_KEY)
LD_API_TOKEN: $(LD_API_TOKEN)
- script: npx --no-install flagrm verify "$FLAG" --json > "$(Agent.TempDirectory)/verify.json"
displayName: Verify the removal
# an advisory /flagrm-review in a fresh session, then:
- script: |
git switch -c "flagrm/remove-$FLAG"
git add -A && git commit -m "chore: remove $FLAG feature flag"
git push origin "flagrm/remove-$FLAG"
az repos pr create --source-branch "flagrm/remove-$FLAG" ...
displayName: Open a pull request
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
The safeguards are the same as on GitHub, and nothing merges without a person:
- The pipeline runs
flagrm verifyitself. If it fails, the job stops before a branch is pushed. - A second, read-only agent reviews the diff.
/flagrm-reviewruns in a new process with no Edit or Write tool, and Bash only forflagrm verifyandgit diff. It is advisory: its findings go into the pull request, and a failed review never blocks it. - One pull request per flag, with the verify report in the description.
5. Azure DevOps details worth knowing
- Add your toolchain. The agent runs your build and tests through
flagrm verify. Add the steps your project needs, such asUseDotNet@2withuseGlobalJson: true. - The 4000-character limit. Azure Repos cuts pull request descriptions at 4000 characters. The pipeline keeps the verify overview whole and shortens only the review to fit.
- Target branch. The pull request targets
$(Build.SourceBranchName), which ismainfor the schedule above. That variable holds only the last segment of the branch name, so for a branch such asrelease/2026it is2026. If you schedule a branch with a/in its name, set--target-branchto the full name. - Build validation. Pull requests from the pipeline go through your branch policies like any other. If a policy requires a build to pass, that build runs on them.
- Job time limits. A removal can take a while, so the job sets a 120-minute timeout. Microsoft-hosted agents on the free tier stop every job after 60 minutes, whatever the timeout says. A paid parallel job allows up to 360 minutes, and a self-hosted agent has no limit.
- Parallel jobs.
maxParallel: 2only helps if your organization has two parallel jobs. Otherwise the removals wait in the queue one after another. Check Organization settings, Pipelines, Parallel jobs before you raise it.
6. Review, merge, then archive
Review each pull request like any other change, and check the places the checks can’t see (see the blind spots). Once the change is deployed, archive the flag in LaunchDarkly. Doing it earlier makes deployed code that still evaluates the flag fall back to its default, which may be the OFF path.
Run the pipeline by hand the first time (Run pipeline) and look at what it opens before you leave it on the schedule. On the first run, a whole backlog of old flags can qualify at once.