Yugank Singh
Yugank Singh

Reputation: 506

Github return empty string as secrets while running actions

When I do

${{ secrets.MY_SECRET }}

it returns empty string,

I am the person committing the changes and its my repository so there should be no issue regarding authorization of secrets, and also cloned it not fork,

this is how my actions job looks like

build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        
      - name: Setup Node.js environment
        uses: actions/[email protected]

      - name: Download Modules
        run: npm ci
      - name: Test
        env:
          TEST_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TEST_SECRET: ${{ secrets.TEST_SECRET }}
        run: |
          echo ${#TEST_GITHUB_TOKEN}
          echo ${#TEST_SECRET}

      - name: React Build 
        run:  npm run build
        env:
          CI: true
          REACT_APP_FIREBASE_API_KEY: ${{ secrets.REACT_APP_FIREBASE_API_KEY }}
          REACT_APP_PIXABAY_API_KEY: ${{ secrets.REACT_APP_PIXABAY_API_KEY }}
          REACT_APP_TEST: 'TESTING'

      - name: Upload a Build Artifact
        uses: actions/[email protected]
        with:
          name: docs
          path: './build'

the TEST_GITHUB_TOKEN returns 40

and TEST_SECRET returns 0

and the REACT_APP_TEST environment variable is working as expected, it means the secrets is the thing that is not being passed

GitHub Repository

Upvotes: 4

Views: 4305

Answers (1)

Yugank Singh
Yugank Singh

Reputation: 506

TL;DR Use Correct Environments to access secrets

basically, there are two places you can put your secrets there are environment secrets and repository secrets, the repository secrets are automatically given to the job but to access the environment you have to explicitly tell it to pass the environment like this

jobs:
  myJob:
    environment: myEnironmentName   
    runs-on: ubuntu-latest
  • you can use any OS

Go to

repo >> settings >> secrets

and check whether your secrets are stored in environment secrets or repo secrets, if they are stored in environment secrets than you have to explicitly access it like in the code above.

I really thank all the community members who commented and helped find the answer, Thanks :)

Upvotes: 8

Related Questions