【发布时间】:2022-01-19 01:39:20
【问题描述】:
我确实需要它是一个环境变量,这专门用于复合操作。
在复合动作中,我尝试了许多不同的设置环境变量的方法。我发现这样做的唯一方法是在步骤本身中使用env:
runs:
using: "composite"
steps:
- name: "A step"
env:
BRANCH_REF: "${{ github.ref }}"
run: echo "The branch is $BRANCH_REF"
shell: bash
不幸的是,我需要动态设置这个变量。在常规操作中,我会执行以下操作:
env:
FOO: "${{ secrets.FOO }}"
#...
- run: echo "FOO=${{ github.event.inputs.foo }}" >> $GITHUB_ENV
if: ${{ github.event.inputs.foo != '' }}
由于我做不到,我尝试了很多其他方法,但都没有奏效。这是我最近的尝试,但也不起作用:
- name: "A step"
run: |
if ${{ github.event.inputs.foo != '' }}
then
echo "Set from manual input: ${{ github.event.inputs.foo }}"
echo "FOO=${{ github.event.inputs.foo }}" >> $GITHUB_ENV
else
echo "Use FOO workflow secret input: ${{ inputs.FOO }}"
echo "FOO=${{ inputs.FOO }}" >> $GITHUB_ENV
fi
echo "foo is $FOO"
shell: bash
我在 GitHub 控制台中得到的输出是:
Run if true
if true
then
echo "Set from manual input: My foo is a good foo"
echo "FOO=My foo is a good foo" >> $GITHUB_ENV
else
echo "Use FOO secret: ***"
echo "FOO=***" >> $GITHUB_ENV
fi
echo "foo is $FOO"
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
Set from manual input: My foo is a good foo
foo is
在最后的输出行上,我得到了foo is ,所以似乎没有设置环境变量 $FOO。
如何在复合动作中动态设置环境变量?
【问题讨论】:
标签: github environment-variables github-actions composite