Skip to content
Latchkey

GitHub Actions secrets cannot be used in if conditions

The secrets context is not available in every key. Job-level if is evaluated before secrets are in scope, so a condition like if: secrets.TOKEN != '' fails to gate as intended.

What this error means

A job or step that should run only when a secret is present runs (or skips) unexpectedly, or the workflow errors that secrets is not a recognized context in that location.

github-actions
Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.DEPLOY_KEY != ''

Common causes

Job-level if cannot read secrets

The secrets context is not available in jobs.<id>.if; the condition errors or never matches.

Gating presence of a secret directly

Conditionals that branch on a secret value leak intent and are not supported at job scope.

How to fix it

Promote the secret to an env or output first

  1. Set a job-level env var from the secret, then branch on the env in a step.
  2. Or compute a boolean output in an early step and gate later steps on that output.
  3. Avoid referencing secrets.* inside jobs.<id>.if.
.github/workflows/deploy.yml
jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      HAS_KEY: ${{ secrets.DEPLOY_KEY != '' }}
    steps:
      - if: env.HAS_KEY == 'true'
        run: ./deploy.sh

How to prevent it

  • Never reference secrets.* in job-level if.
  • Convert secret presence to an env var or step output, then branch on that.

Frequently asked questions

What causes "secrets in if conditions"?
The secrets context is not available in jobs.<id>.if; the condition errors or never matches.
How do I fix secrets in if conditions?
Promote the secret to an env or output first

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card