英文:
How to access GitHub "variables" from GitHub Actions scripts? (env. doesn't work)
问题
我正试图访问GitHub存储库级别和组织级别设置的GitHub "Actions"脚本的SECRETS和VARIABLES。
以下是脚本:
name: CI (pip)
on: [push, pull_request]
jobs:
build:
strategy:
matrix:
os: ['ubuntu-latest']
python-version: [3.9] # 在Dreamhost上安装的版本
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: First Test
run: |
echo ORG_NAME = ${{ env.ORG_NAME}}
echo MY_NAME = ${{ env.MY_NAME}}
echo MY_SECRET = ${{ secrets.MY_SECRET }}
- name: Second Test
env:
ORG_NAME_ENV: ${{ env.ORG_NAME }}
MY_NAME_ENV: ${{ env.MY_NAME }}
MY_SECRET: ${{ secrets.MY_SECRET }}
run: |
echo ORG_NAME_ENV = $ORG_NAME_ENV
echo MY_SECRET = $MY_SECRET
echo SHA256 = `echo $MY_SECRET | openssl sha256`
这只是不起作用。secrets.MY_SECRET
被设置,但env.ORG_NAME
和env.MY_NAME
未被设置。
以下是配置的样子:
组织级别的Actions secrets和variables:
存储库secrets:
存储库级别的variables:
我可以访问secrets,但无法访问variables。
以下是输出的样子:
哦,MY_SECRET=secret
,以防你不想做哈希搜索。
英文:
I'm trying to access GitHub SECRETS and VARIABLES set at the Repo level and at the Organization level for a GitHub "Actions" script.
Here is the script:
name: CI (pip)
on: [push, pull_request]
jobs:
build:
strategy:
matrix:
os: ['ubuntu-latest']
python-version: [3.9] # installed version on Dreamhost
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: First Test
run: |
echo ORG_NAME = ${{ env.ORG_NAME}}
echo MY_NAME = ${{ env.MY_NAME}}
echo MY_SECRET = ${{ secrets.MY_SECRET }}
- name: Second Test
env:
ORG_NAME_ENV: ${{ env.ORG_NAME }}
MY_NAME_ENV: ${{ env.MY_NAME }}
MY_SECRET: ${{ secrets.MY_SECRET }}
run: |
echo ORG_NAME_ENV = $ORG_NAME_ENV
echo MY_SECRET = $MY_SECRET
echo SHA256 = `echo $MY_SECRET | openssl sha256`
This just doesn't work. The secrets.MY_SECRET
gets set, but env.ORG_NAME
and env.MY_NAME
do not get set.
Here is what the config looks like:
Organization level actions secrets and variables:
Repo secrets:
Repo level variables:
I can access the secrets, but not the variables.
Here is what the output looks like:
Oh, MY_SECRET=secret
, in case you don't want to do the hash search.
答案1
得分: 1
配置变量通过 vars
上下文访问,而不是 env
。
参见:
英文:
Configuration variables are accessed via the vars
context, not env
.
See:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论