DEV Community

CodeNameGrant
CodeNameGrant Subscriber

Posted on

Flip Your CI Like a Switch: Instantly Toggle Flags with GitHub Actions Variables

Ever wish you could tweak your CI pipeline on the fly—change logging levels, skip caching, or toggle features—without touching a single line of code or YAML?

With GitHub Actions variables, you can.


What Are GitHub Actions Variables?

Like GitHub Secrets (secrets), Variables (vars) are simple key-value pairs you define in your repository.

You can use them to control workflow behavior without committing changes, making them perfect for feature flags, build tweaks, or environment switches.


Example: Controlling Nx Build Flags

Imagine you want to control verbose logging and cache usage for an nx build command.

In your repo settings under Secrets and Variables → Actions → Variables (tab) define the following:

  • NX_VERBOSE_MODE: true or false
  • NX_USE_NX_CACHE: true or false

Then use them directly in your workflow:

- name: Build
  shell: bash
  run: >
    npx nx build app-name
    ${{ vars.NX_VERBOSE_MODE == 'true' && '--verbose' || '' }}
    ${{ vars.NX_USE_NX_CACHE != 'true' && '--skip-nx-cache' || '' }}
Enter fullscreen mode Exit fullscreen mode

Using run: > (folded style) combines all lines into a single line, replacing line breaks with a space. Its great in this use-case making the command easy to read.

Now you can toggle flags directly from the Variables tab—no pull requests, no commits, just instant control.

Top comments (0)