如何从GitHub Actions脚本中访问GitHub的“variables”?(env.不起作用)

huangapple go评论109阅读模式
英文:

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_NAMEenv.MY_NAME未被设置。

以下是配置的样子:

组织级别的Actions secrets和variables:
如何从GitHub Actions脚本中访问GitHub的“variables”?(env.不起作用)

存储库secrets:
如何从GitHub Actions脚本中访问GitHub的“variables”?(env.不起作用)

存储库级别的variables:
如何从GitHub Actions脚本中访问GitHub的“variables”?(env.不起作用)

我可以访问secrets,但无法访问variables。

以下是输出的样子:
如何从GitHub Actions脚本中访问GitHub的“variables”?(env.不起作用)

哦,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:
如何从GitHub Actions脚本中访问GitHub的“variables”?(env.不起作用)

Repo secrets:

如何从GitHub Actions脚本中访问GitHub的“variables”?(env.不起作用)

Repo level variables:

如何从GitHub Actions脚本中访问GitHub的“variables”?(env.不起作用)

I can access the secrets, but not the variables.

Here is what the output looks like:

如何从GitHub Actions脚本中访问GitHub的“variables”?(env.不起作用)

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:

huangapple
  • 本文由 发表于 2023年8月5日 05:12:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76839128.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定