Skip to content

Feature flags in CI/CD pipelines: checks, code references and flags as code

What a CI/CD pipeline should do with feature flags: validate flag files, lint them, catch flag keys that don't exist, find stale flags with code references, and manage flags as code with Terraform or Git, with a GitHub Actions workflow and checks we ran against valid and broken files.

8 min read

Short answer: Let the pipeline check flags like code: validate flag files against their schema, fail the build when code uses a flag key that doesn't exist, test both sides of each flag, and report where flags are used so stale ones get removed. Keep turning flags on as a separate, controlled step, not something every deploy does.

What should a CI/CD pipeline do with feature flags?

Job When What it catches Tools
Validate flag files Every pull request Broken syntax and missing fields (JSON schema); also unknown variations (GO Feature Flag lint) flagd's JSON schema, lint in the GO Feature Flag CLI
Check flag keys used in code Every pull request A typo in a key, which returns the default A small script (below), or typed accessors generated by the OpenFeature CLI
Test both sides of each flag Every pull request The path that's off rotting while nobody runs it Test providers; see testing code that uses flags
Check flag key names Every pull request Keys that break your convention Naming check script
Report code references On push or the main branch; flag diffs on pull requests Where each flag is used; flags deleted in the tool but still in code LaunchDarkly ld-find-code-refs, GrowthBook gb-find-code-refs, ConfigCat configcat scan
Apply flag configuration After merge, with review Flag changes that skip review (applying overwrites changes made elsewhere; a scheduled terraform plan -detailed-exitcode detects them) Terraform providers, vendor CLIs, flag files in Git

What checks can I run on flag files in CI?

When flags live in files in your repository (flagd, GO Feature Flag, or files exported from a vendor), the pipeline can reject a broken file before it ships. We ran the checks against valid and deliberately broken files on 15 November 2026:

Check Valid input Broken input
flagd file against flagd's JSON schema, with ajv-cli 5.0.0 Exit 0, "valid" Exit 1: missing variants, and (with --all-errors) a state of "ON"
Same, with a defaultVariant and a targeting result that aren't among the variants Exit 0, "valid": JSON Schema can't check one field against another
GO Feature Flag CLI v1.58.1, lint Exit 0, "Valid GO Feature Flag configuration" Exit 1: "invalid variation: missing_variation does not exist"
Flag keys used in code defined in the flagd file Exit 0 Exit 1: ops_disable_recomendations (a typo) isn't defined

So schema validation catches structure, not meaning; for flagd files, a variation that doesn't exist only shows up when the flag is evaluated. The script, the flag files, the schema copies and the results are published. flagd's schema lives at https://flagd.dev/schema/v0/flags.json and references ./targeting.json next to it; commit copies of both (we use schema/) so the check doesn't depend on the network.

The key check is the one most teams lack. A misspelled key doesn't fail the build or throw: the SDK returns the default value, and the feature never turns on. Only the evaluation details (FLAG_NOT_FOUND in OpenFeature's get...Details), error hooks or provider logs show it. This script compares keys passed to OpenFeature's get...Value and get...Details with the keys in a flagd file:

// Fails when code uses a flag key that isn't defined in the flag file (typos return the default silently).
// Usage: node check-flag-keys.mjs <flagd-file.json> <src-dir>
import { readFileSync, readdirSync, lstatSync } from 'node:fs'
import { join } from 'node:path'

const [flagFile, srcDir] = process.argv.slice(2)
const defined = new Set(Object.keys(JSON.parse(readFileSync(flagFile, 'utf8')).flags))
const CALL = /\bget(?:Boolean|String|Number|Object)(?:Value|Details)\(\s*(['"`])((?:(?!\1).)*)\1/gs

function* files(dir) {
  for (const name of readdirSync(dir)) {
    const path = join(dir, name)
    if (name === 'node_modules' || name.startsWith('.')) continue
    if (lstatSync(path).isDirectory()) yield* files(path)
    else if (/\.(c|m)?[jt]sx?$/.test(name)) yield path
  }
}

let missing = 0
for (const file of files(srcDir)) {
  const source = readFileSync(file, 'utf8')
  for (const m of source.matchAll(CALL)) {
    if (m[1] === '`' && m[2].includes('${')) continue
    if (!defined.has(m[2])) {
      console.error(`${file}:${source.slice(0, m.index).split('\n').length}: flag "${m[2]}" is not defined in ${flagFile}`)
      missing++
    }
  }
}
process.exit(missing ? 1 : 0)

Limits: it only sees string keys in JavaScript and TypeScript files, written directly in OpenFeature calls, so keys held in constants, framework hooks such as useBooleanFlagValue and other SDKs' method names need their own patterns. With a hosted flag tool, export the list of flag keys from its API in an earlier step and compare against that instead. A sturdier approach is generated code: the OpenFeature CLI (v0.4.1) generates typed flag accessors from a flag manifest for TypeScript, React, Go, C# and other languages, so a misspelled flag becomes a compile error.

What does the GitHub Actions workflow look like?

name: Flag checks
on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  flags:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 22
      - name: Validate the flagd file against its JSON schema
        run: >-
          npx --yes -p ajv-cli@5.0.0 -p ajv-formats@3.0.1 ajv validate --spec=draft7 -c ajv-formats
          -s schema/flags.json -r schema/targeting.json -d flags/flags.flagd.json --strict=false
      - name: Lint the GO Feature Flag file
        run: docker run --rm -v "$PWD/flags:/flags" gofeatureflag/go-feature-flag-cli:v1.58.1 lint /flags/flags.goff.yaml --format yaml
      - name: Check that flag keys used in code exist
        run: node check-flag-keys.mjs flags/flags.flagd.json src

It expects schema/, flags/, src/ and check-flag-keys.mjs committed at the repository root. We checked the workflow with actionlint 1.7.12 (no problems) and ran its ajv command exactly as written on Node.js 22 with a fresh npm cache (exit 0 for the valid file, 1 for the broken one); the other steps ran locally, and we didn't run the workflow on GitHub's runners (workflow file). GO Feature Flag also publishes a lint GitHub Action (gofeatureflag-lint-action, v1.1.0) you can use instead of docker run. Keep only the steps for the flag format you use.

How do code references find stale flags?

Code reference tools scan the repository from CI and report where each flag key appears, so you can see which flags are no longer used, or which flags were deleted in the tool but still sit in code:

Tool Scanner What it does Credentials
LaunchDarkly ld-find-code-refs (Docker, Homebrew; GitHub Actions, CircleCI, Bitbucket and GitLab integrations); a separate pull request action Uploads references to LaunchDarkly; searches Git history for flags that became extinct (--lookback, 10 commits by default); --dryRun with --outDir writes a CSV without uploading; --contextLines below 0 sends no source code; the pull request action reports flags added or removed in a pull request A personal access token with writer-level access, or a custom role on the code-reference-repository resource
GrowthBook gb-find-code-refs (a fork of LaunchDarkly's) Takes a JSON list of flag keys and writes a JSON report, which you post to GrowthBook's API Only for the upload step
ConfigCat configcat scan in the ConfigCat CLI; configcat/scan-repository@v2 GitHub Action Uploads scan reports per branch; warns about keys of flags deleted in the last 180 days that still appear in code ConfigCat Management API credentials
GitLab feature flags "Search code references" in the UI (Premium and Ultimate) Finds where a flag is used

Sources: ld-find-code-refs and its configuration, gb-find-code-refs, ConfigCat code references and GitHub Action, GitLab feature flags. Full scans usually run on pushes or the main branch (ConfigCat's example runs on every push), while pull request checks show which flags a change adds or removes. See stale feature flags for what to do with the results.

How do I manage flags as code?

Three approaches, from most to least version-controlled:

  • Flag files in Git. flagd and GO Feature Flag read flags from files, so a flag change is a pull request, reviewed and validated like code, and deployed by the pipeline. You give up a UI for non-engineers and instant changes (see self-hosted vs SaaS).
  • Terraform. Several vendors publish Terraform providers, so flag definitions, environments and segments can be reviewed in pull requests and applied after merge. Check whether a provider covers targeting rules, or only flag definitions, before relying on it for releases.
  • Vendor CLIs and APIs. The ConfigCat CLI, for example, can create flags and change their values per environment from a pipeline, with credentials in environment variables.

Terraform providers on the Terraform Registry, checked on 15 November 2026:

Provider Latest version Released Registry tier
launchdarkly/launchdarkly 3.3.0 29 Oct 2026 Partner
configcat/configcat 5.10.0 27 Aug 2026 Partner
Flagsmith/flagsmith 0.12.0 26 Aug 2026 Partner
Unleash/unleash 3.4.7 14 Oct 2026 Community
statsig-io/statsig 2.2.1 12 Dec 2025 Community
PostHog/posthog 1.0.30 13 Nov 2026 Community
harness/harness 0.47.8 11 Nov 2026 Community
devcyclehq/devcycle 1.0.2 29 Mar 2023 Partner

Source: the Terraform Registry API for each provider. "Community" is the registry's tier label; the Unleash, Statsig, PostHog and Harness providers are published from the vendors' own GitHub organizations. DevCycle's provider hasn't had a release since March 2023. GrowthBook publishes no provider of its own; third-party community providers exist on the registry (for example Flex-O-SAS/growthbook 2.0.3).

Should the pipeline turn flags on?

Usually not as part of every deploy. The point of a flag is that releasing a feature is separate from deploying code (trunk-based development). Common patterns:

  • Deploy with the flag off, then turn it on in a separate, reviewed step: a flag change with approval in the flag tool, a pull request to a flag file, or a manual pipeline stage.
  • Turn flags on in test environments automatically to run end-to-end tests with the new path, and leave production for a person or a rollout policy.
  • Don't confuse flags with deployment canaries. Tools like Argo Rollouts and Flagger shift traffic between two deployed versions (canary, blue-green); flags switch behavior inside one version. They complement each other.
  • Record who changed what. Flag changes made outside the pipeline need their own audit log; see approvals and audit logs.
  • Keep SDK keys and API tokens in the CI secret store, and use read-only keys wherever the job only reads flags.

What about GitLab's built-in feature flags?

GitLab includes feature flags in all tiers, with an Unleash-compatible API, so Unleash SDKs connect to GitLab. Strategies include all users, percent rollout, percent of users, user IDs and user lists, and GitLab limits each project to 50 flags on GitLab.com Free, 150 on Premium, 200 on Ultimate and 200 self-managed. GitLab's docs note that the Unleash Proxy reaches end of life on 26 November 2026 and that Unleash Edge isn't compatible with GitLab (GitLab feature flags); see also Unleash Edge's open-source end of life. All tools are in the directory.