如何在Github动作中设置一个env secret ?



我想访问我的。env中的env变量。当然,我们不能提交。env文件。

所以我在我的Github中添加了一个名为MONGODB_PASSWORD的操作秘密。但是当我试图访问这个秘密时,它没有像预期的那样工作。

我该怎么做呢?

这是我在。yml

中的内容
name: Node.js CI
on:
push:
branches: ['master']
pull_request:
branches: ['master']
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
env:
MONGODB_PASSWORD: ${{ secrets.MONGODB_PASSWORD }} // Setting the secret here
- run: npm ci
- run: npm run build --if-present
- run: npm run lint
- run: npm run test
- run: npm run test:e2e

尝试将env设置为作业级别而不是步骤级别:

name: Node.js CI
on:
push:
branches: ['master']
pull_request:
branches: ['master']
jobs:
build:
runs-on: ubuntu-latest
env:
MONGODB_PASSWORD: ${{ secrets.MONGODB_PASSWORD }} // Setting the secret here
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm run lint
- run: npm run test
- run: npm run test:e2e

相关内容

  • 没有找到相关文章

最新更新