4

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

asked Jun 14, 2021 at 14:27
9
  • 3
    @GuiFalourd ${#var} prints the length of var, that shouldn't be the problem. Commented Jun 14, 2021 at 14:46
  • 3
    Just to be sure: you've added a TEST_SECRET to your repository, yes? GITHUB_TOKEN is special in that it's predefined. Commented Jun 14, 2021 at 14:47
  • 2
    Have you tried running with debug logging enabled? Commented Jun 14, 2021 at 14:50
  • 3
    Also, you mix up MY_SECRET and TEST_SECRET in the question, make sure you use the right one. Commented Jun 14, 2021 at 14:51
  • 2
    Have you read the following question and checked if you are using an Environment secret or a Repository secret? stackoverflow.com/questions/66521958/… Commented Jun 14, 2021 at 20:38

1 Answer 1

8

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 :)

answered Jun 14, 2021 at 23:33
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.