问题描述
我正在尝试创建GitHub Actions工作流,其中一个作业的 environment
设置具有动态值. https://docs.github.com/en/actions/reference/environments我在此工作流程中有两项工作.第一个作业确定第二个作业将在哪个 environment
中运行,而这又取决于该Actions作业从哪个git分支运行.
I'm trying to make a GitHub Actions workflow where one job has a dynamic value to its environment
setting. https://docs.github.com/en/actions/reference/environments I have two jobs in this workflow. The first job determines which environment
the second job will run in, and this is in turn based on which git branch the Actions job is run from.
这是我天真地尝试使其工作,但出现错误提示
This is my naive attempt to make it work, but I get an error which says
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 }}
是否有可能实现我想做的事情?我的最终目标是为三个不同的应用程序环境(测试,质量检查和产品)创建一个工作流文件,其中每个应用程序环境使用单独的操作 environment
.(我知道术语令人困惑)
Is it possible to achieve what I'm trying to do? My end goal is to have a single workflow file for three different app environments (test, QA and prod), where each app environment uses a separate Actions environment
. (terminology gets confusing, I know)
推荐答案
您尝试过
> use-environment:
> runs-on: ubuntu-latest
> needs: [get-environment]
> environment:
> name: ${{ needs.get-environment.outputs.environment_name }}
这篇关于在GitHub Actions工作流程作业中为Environment使用动态输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!