我有这个GitHub工作流程,需要在哪些跑步者运行的情况下进行参数化。因此,在YAML文件中,我尝试了:
# ...
jobs:
process:
name: Process
runs-on: ${{ secrets.GH_RUNNER_TAG }}
# ...
但是,我会收到此错误:
工作流程无效。 。位于表达式中的位置1:secrets.gh_runner_tag
该元素不可用的秘密注入吗?还有其他选择吗?该值不需要是秘密,但是我需要在一个地方将其放在一个地方,而不是每次跑步者标签都会更改数百个YAML文件...
edit1:
我尝试过,如所建议的 guifalourd
,在工作流级别上创建一个环境变量,该变量可以容纳秘密:
env:
RUNNER_LABEL: ${{ secrets.GH_RUNNER_TAG }}
jobs:
analyze:
name: Analyze
runs-on: $RUNNER_LABEL
并且它不起作用。动作被卡住了。我尝试使用:
$ runner_label->被卡住了
“ $ runner_label” - >也被卡住了
$ {env.runner_label}} - >操作没有启动,输出错误:
工作流程无效。 。位于表达式中的位置1:env.runner_label
此外,我已经检查了通过在运行设置的有效的,硬编码的值和设置第一步AS:
steps:
- name: Test
run: echo "$RUNNER_LABEL"
产生“ ***” - 证明GitHub已自动输出并自动编辑了一个秘密。
I have this GitHub workflow that I need to parameterize on which runners runs. So in the YAML file I tried:
# ...
jobs:
process:
name: Process
runs-on: ${{ secrets.GH_RUNNER_TAG }}
# ...
However, I get this error:
The workflow is not valid. .github/workflows/action.yml (Line: 12, Col: 14): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.GH_RUNNER_TAG
Is the secrets injection not available for this element? Is there some other alternative? The value does not need to be a secret but I need to have it in one place and not edit hundreds of YAML files everytime the runner tag would change...
EDIT1:
I've tried, as GuiFalourd
suggested, to create an environment variable at the workflow level which would hold the secret:
env:
RUNNER_LABEL: ${{ secrets.GH_RUNNER_TAG }}
jobs:
analyze:
name: Analyze
runs-on: $RUNNER_LABEL
And it doesn't work. The action gets stuck. I tried using:
$RUNNER_LABEL -> gets stuck
"$RUNNER_LABEL" -> gets stuck, too
${{ env.RUNNER_LABEL }} -> action does not start, outputs error:
The workflow is not valid. .github/workflows/action.yml (Line: 14, Col: 14): Unrecognized named-value: 'env'. Located at position 1 within expression: env.RUNNER_LABEL
Furthermore, I've checked that the env var is properly assigned, by placing a valid, hard-coded value for runs-on
and setting first step as:
steps:
- name: Test
run: echo "$RUNNER_LABEL"
which produces "***" - proof that a secret has been output and redacted automatically by GitHub.
发布评论
评论(3)
这是可以使用可重复使用的工作流来实现的接受呼叫者的输入。
我们可以将其命名为“过程”的主要管道将使用共享代码库/管道,让我们称其为“通用”,可以接受输入,其中一个输入可以是
runs-on-On-On-On
值。例如
This is achievable using Reusable Workflow by configuring the "called" workflow to accept inputs from the caller.
The main pipeline which we can name it as "process" will use a shared codebase/pipeline lets call it "common" which can accept inputs, one of these inputs can be the
runs-on
value.For example
在不使用参数化工作流的情况下找到了替代方案。这在使用
vars
的同时可以直接如示例 不。最终的工作流将看起来像这样:
Found an alternative without using parameterized workflows. This works while using
vars
directly as documented in the example does not.The final workflow will look something like this:
尝试以下操作:
Try this :