简体   繁体   English

Github 在运行操作时返回空字符串作为机密

[英]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/setup-node@v2.1.5

      - 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/upload-artifact@v2.2.3
        with:
          name: docs
          path: './build'

the TEST_GITHUB_TOKEN returns 40 TEST_GITHUB_TOKEN 返回 40

and TEST_SECRET returns 0并且 TEST_SECRET 返回 0

and the REACT_APP_TEST environment variable is working as expected, it means the secrets is the thing that is not being passed并且 REACT_APP_TEST 环境变量按预期工作,这意味着秘密是没有被传递的东西

GitHub Repository GitHub 存储库

TL;DR Use Correct Environments to access secrets TL;DR 使用正确的环境访问机密

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 Go 至

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:)我真的很感谢所有评论并帮助找到答案的社区成员,谢谢:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM