我確實需要它是一個環境變數,這是專門針對復合操作的。
在復合操作中,我嘗試了許多不同的設定環境變數的方法。我發現這樣做的唯一方法是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 沒有設定。
如何在復合操作中動態設定環境變數?
uj5u.com熱心網友回復:
您遇到的問題是,呼叫echo "FOO=${{ github.event.inputs.foo }}" >> $GITHUB_ENVGitHub 操作腳本步驟不會在當前步驟的腳本中設定該變數,如果您展開下一步的 env 標頭,您應該會看到動態設定的環境變數進入該步驟
我通常做的是這樣的:
FOO="${{ github.event.inputs.foo }}"
echo "FOO=${FOO}" >> $GITHUB_ENV
因此,您設定了一個FOO在當前步驟的腳本中呼叫的變數(使其在同一步驟的后續行中可用)并將其匯出以供以后的步驟使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/386577.html
上一篇:Github推送提交問題
