Skip to content

Home / Blog / Runners and limits

How do I fix "Unrecognized named-value: 'secrets'" in GitHub Actions?

"Unrecognized named-value: 'secrets'" means a context is used at a workflow key where it is not available. Which contexts work where, and four rewrites.

“Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.TOKEN != ''” means the expression uses a context that does not exist at that key of the workflow file. secrets is not available in any if, and env is not available in runs-on. Move the value to a key that allows it, or use a context that is allowed there. A misspelt name gives the same message.

In short
  • The expression uses a context that is not available at that workflow key, or a misspelt name.
  • The position in the message is the character of the expression where the name starts.
  • secrets is not available in a job's if or a step's if: set it as job-level env and test env in the step.
  • Pass a secret to a reusable workflow under secrets, not with.
  • env is not available in runs-on: use vars, or an output of an earlier job through needs.

The name in quotes is the context GitHub did not accept, the position is the character in the expression where it starts, and the expression is printed after it. GitHub rejects the whole file, so no job runs. This post has the table of which contexts are allowed where, four cases of it, and the rewrite for each.

What does “Unrecognized named-value” mean?

In GitHub’s expression parser a named value is the word at the start of a reference: github, env, secrets, matrix and so on. The parser is given the list of names that are valid for the key it is reading, and a name outside the list is an unrecognised named value, whether you misspelt it or it is a real context that does not exist yet at that point. GitHub’s contexts reference says it plainly: different contexts are available at different places in a workflow, and secrets may only be used at certain places within a job.

Which contexts are available where?

GitHub’s contexts reference has a table with one row for every workflow key. These are the rows for the keys this post covers. The middle column is copied from the table, and the last names contexts that are not in that row.

Workflow keyContexts availableNot available, for example
jobs.<job_id>.ifgithub, needs, vars, inputssecrets, env, matrix
jobs.<job_id>.steps.ifgithub, needs, strategy, matrix, job, runner, env, vars, steps, inputssecrets
jobs.<job_id>.runs-ongithub, needs, strategy, matrix, vars, inputsenv, secrets
jobs.<job_id>.with.<input_id>github, needs, strategy, matrix, inputs, varssecrets, env
jobs.<job_id>.strategygithub, needs, vars, inputsenv, secrets, matrix
env (top of the workflow)github, secrets, inputs, varsenv, matrix, needs
concurrency (top of the workflow)github, inputs, varsenv, secrets, matrix

Inside a step’s run, with and env nearly everything is available, secrets included, which is why the same expression works in one place and is refused two lines up.

How do I use a secret in an if condition?

You cannot, and GitHub’s documentation gives the way round it: set the secret as an environment variable on the job, then test the variable in the step’s condition. A step’s if has the env context.

jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
    steps:
      - if: env.DEPLOY_KEY != ''
        run: ./deploy.sh

This works for steps only. A job’s own if has neither secrets nor env, so a whole job cannot be switched on a secret directly; a report asking for that on GitHub’s runner repository was closed with a maintainer saying it should not be supported. Switch the job on something that is available there instead: a configuration variable through vars, or an output of an earlier job through needs, as in the last example below.

How do I pass a secret to a reusable workflow?

Under secrets, not under with. When a job calls a reusable workflow, its with values may use only the contexts in the table above, and secrets is not one of them. The job has a separate secrets map for this, and the names in it must match the ones the called workflow declares.

jobs:
  call:
    uses: octo-org/example-repo/.github/workflows/called.yml@main
    with:
      environment: staging
    secrets:
      token: ${{ secrets.TOKEN }}

secrets: inherit passes every secret the caller has without naming them. The post on reusable workflows or composite actions has more on how the two receive their inputs.

Why can’t I use env in runs-on?

Because the env context is not in the row for runs-on in GitHub’s table. The same goes for a job’s if, strategy, concurrency and container. There are two rewrites. If the value is a setting, store it as a configuration variable and read it with vars, which is available at every key in the table. If the value has to be computed, compute it in a small first job and read that job’s output through needs:

env:
  RUNNER: ubuntu-latest

jobs:
  pick:
    runs-on: ubuntu-latest
    outputs:
      runner: ${{ steps.pick.outputs.runner }}
    steps:
      - id: pick
        run: echo "runner=$RUNNER" >> "$GITHUB_OUTPUT"
  build:
    needs: pick
    runs-on: ${{ needs.pick.outputs.runner }}
    steps:
      - run: make

matrix in a job’s if is the same mistake in another place: matrix is not in that row either. Put the condition on the steps, or leave the combination out of the matrix with exclude, which the matrix reference covers.

What if the name is spelt wrong?

Then the name in quotes is your spelling: secret for secrets, input for inputs, step for steps. Check that first, since it takes a second. actionlint, an open-source workflow checker, finds both kinds before you push: for each of the broken workflows in this post it named the context and listed the ones allowed at that key.

actionlint .github/workflows/deploy.yml
# .github/workflows/deploy.yml:6:13: context "secrets" is not allowed here. available contexts are "github", "inputs", "needs", "vars". see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details [expression]

Two neighbouring messages: a file that does not parse at all gives “You have an error in your yaml syntax”, and a step with nothing to do gives “every step must define a `uses` or `run` key”. The security hardening post covers handling secrets once they reach a step.

GitHub evaluates these expressions when it reads the workflow file, so this error is the same whichever runner the jobs name, ours included. Every size we run, with its memory, disk and rate a minute, is on our managed GitHub Actions runners page.

Sources

Frequently asked questions

How do I fix "Unrecognized named-value: 'secrets'" in GitHub Actions?

Move the value to a key where that context is available, or use one that is allowed there. secrets is not available in any if, and env is not available in runs-on. The position, such as 1, is where the name starts in the expression.

How do I use a secret in an if condition?

You cannot use it directly. GitHub's documentation says to set the secret as a job-level environment variable and test that variable in the step's condition. A job's own if has neither secrets nor env, so use vars or an earlier job's output there.

How do I pass a secret to a reusable workflow?

Under the calling job's secrets map, not under with, where the secrets context is not available. The names must match the ones the called workflow declares. secrets: inherit passes every secret the caller has.

What if the name is spelt wrong?

Then the name in quotes is your spelling, such as secret for secrets. Any name the parser does not know at that key gives this message. actionlint reports both a misspelt name and a context used where it is not allowed.

Move your CI onto our runners with one line

Change one line, watch your own build, then decide.

Connect GitHub

Card required: a $5.00 authorisation, released at once and never charged. 3,000 minutes a month at 2 vCPU are included.

.github/workflows/ci.yml
jobs: test:removed: runs-on: ubuntu-latestadded: runs-on: runnersio-4vcpu-ubuntu-latest steps: - uses: actions/checkout@v4 - run: make testadded: build:added: runs-on: runnersio-32vcpu-ubuntu-latest