【发布时间】:2021-04-25 19:20:56
【问题描述】:
我正在尝试创建一个 GitHub Actions 工作流程,其中一项作业对其environment 设置具有动态值。 https://docs.github.com/en/actions/reference/environments我在这个工作流程中有两个工作。第一个作业决定了第二个作业将在哪个environment 中运行,而这又取决于 Actions 作业从哪个 git 分支运行。
这是我让它工作的天真的尝试,但我收到一个错误提示
(第 29 行,第 18 列):无法识别的命名值:“需要”。位于表达式中的位置 1:needs.get-environment.outputs.environment_name
name: Environments
on:
push:
workflow_dispatch:
jobs:
get-environment:
runs-on: ubuntu-latest
outputs:
environment_name: ${{ steps.get_environment.outputs.environment_name }}
steps:
- id: get_environment
run: |
if [ "$GITHUB_REF" = "refs/heads/test" ]
then
echo "::set-output name=environment_name::test"
elif [ "$GITHUB_REF" = "refs/heads/qa" ]
then
echo "::set-output name=environment_name::qa"
elif [ "$GITHUB_REF" = "refs/heads/master" ]
then
echo "::set-output name=environment_name::production"
fi
use-environment:
runs-on: ubuntu-latest
needs: [get-environment]
environment: ${{ needs.get-environment.outputs.environment_name }}
steps:
- uses: actions/checkout@v2
- name: Run a one-line script
run: echo ${{ secrets.ENV_DEPENDENT_SECRET }}
是否有可能实现我想要做的事情?我的最终目标是为三个不同的应用程序环境(测试、QA 和产品)提供一个工作流文件,其中每个应用程序环境使用单独的操作environment。 (术语变得混乱,我知道)
【问题讨论】:
-
看起来在 repo 上也有一个问题:github.com/actions/runner/issues/998
标签: github-actions