GitHub Octodex (octocat) from

GitHub Action fails with “The GITHUB_TOKEN environment variable was not set”

This post was most recently updated on February 19th, 2022.

3 min read.

Another day, another thing that I am trying to do on GitHub (and partially failing), and another blog post! This time I was configuring a build and ran into trouble. This article describes one possible fix to an issue where an error is thrown along the lines of “The GITHUB_TOKEN environment variable was not set”.

"All checks have failed" - pretty disheartening.
“All checks have failed” – pretty disheartening.

As a backstory: I have a long history with Azure DevOps, and have maintained a kind of a love-hate -relationship (that maybe gravitates slightly more on the rosy side of things) for at least since it was called VSO (Visual Studio Online) or VSTS (Visual Studio Team Services). But now I’ve found myself moving my personal projects to GitHub more and more.

And that’s when I run into issues – obviously :)


Okay, so let’s dig in. What went wrong for me?

I was configuring a build for my .NET 5 application using GitHub Actions. When I added a step for publishing a release, I was using the gh-action-auto-release by CupOfTea696 – and ran into issues. The build started failing.

Release -step of my GitHub Action failing for my .NET 5 build.
Release -step of my GitHub Action failing for my .NET 5 build.

The log for this step – Release – contains something like below (this sample is obviously for this particular step, and yours will vary):

(()=>{var e={5265:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e),r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});const o=n(r(2087)),s=r(4570);function i(e,t,r){const n=new a(e,t,r);process.stdout.write(n.toString()+o.EOL)}t.issueCommand=i,t.issue=function(e,t=""){i(e,{},t)};class a{constructor(e,t,r){e||(e="missing.command"),this.command=e,,this.message=r}toString(){let e="::"+this.command;if(>0){e+=" ";let r=!0;for(const n in{const[n];o&&(r?r=!1:e+=",",e+=${n}=${t=o,s.toCommandValue(t).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")})}}var t;return e+=`::${function(e){return s.toCommandValu
The GITHUB_TOKEN environment variable was not set

So “The GITHUB_TOKEN environment variable was not set” – what’s that?


Obviously, there could be other reasons. I suppose. But here’s what I figured: The step you’re trying to perform is probably built by someone else, and that someone else (for whatever reason) decided to depend on environment variable GITHUB_TOKEN instead of the built-in secrets.GITHUB_TOKEN (which is populated for GitHub Actions automatically).

This is probably implemented this way to avoid confusion and issues when having to use tokens with multiple scopes and permissions – and perhaps for backward compatibility or some conflict avoidance reasons?

Don’t get me wrong: I’m not trying to criticize the developers. I don’t know GitHub Actions development well enough to know whether there are a gazillion reasons to do this or not :)

And hey – fixing something like this is easy, right?


Okay, so turns out it actually IS really easy. Follow the steps below:

Time needed: 5 minutes.

How to fix the “GITHUB_TOKEN environment variable” issue in GitHub Actions?

  1. Open your workflow definition file (.yml)

    Usually in a folder called .github/workflows under your repository.

  2. Add your GITHUB_TOKEN as an environment variable

    You can usually do this either for the step or for your whole workflow. An example of the former might look something like this:
    - name: mystep
    uses: ....

    This – essentially – exposes the global, shared, built-in variable secrets.GITHUB_TOKEN for the step in your build as an environment token called GITHUB_TOKEN.
    secrets.GITHUB_TOKEN mapped to an environment variable called - yes, you guessed it - GITHUB_TOKEN.

  3. (OPTIONAL) If any of your steps need the same variable, make it shared!

    This might look something like shown below:
    name: .NET 5 CI
    on: [push]
    runs-on: windows-latest
    name: .NET 5 Application
    - name: The step that relies on the token

And yeah, it was really that easy, at least for me.

Full sample

This is a full sample showing how to share the token:

name: .NET 5 CI

on: [push]


    runs-on: windows-latest
    name: .NET 5 Application
      - uses: actions/[email protected]
      - name: Setup dotnet
        uses: actions/[email protected]
          dotnet-version: '5.0.101' # Check for latest at link at .NET 5 download page
      - run: dotnet build
      - run: dotnet test
      - name: Publish
        run: dotnet publish
      - name: Upload WebApp1 Build Artifact
        uses: actions/[email protected]
         name: desktop
         path: <omitted>
      - name: Release
        uses: CupOfTea696/[email protected] # This step requires GITHUB_TOKEN


0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments