英文:
Use env context within uses defined jobs
问题
With a job
defined by uses
keyword.
使用uses
关键字定义的job
。
Is it possible to use workflow defined env
context?
是否可以使用工作流定义的env
上下文?
If not, is there anyway to define variables in one place or pass context to share workflow env context without having to repeat variables jobs
?
如果不能,是否有办法在一个地方定义变量或传递上下文以共享工作流的env
上下文,而不必重复jobs
中的变量?
Sample:
示例:
name: Build and Publish Helm charts
名称:构建和发布Helm图表
on:
push:
branches:
- "main"
env:
FOO: BAR
jobs:
test:
uses: '.github/workflows/test.yaml'
with:
FOO: ${{ env.FOO }}
While I would expect test.yaml
to take BAR
in the FOO
input, testing above scripts throws an Unrecognized named-value: 'env'
error.
尽管我希望test.yaml
在FOO
输入中使用BAR
,但上面的测试脚本会引发“未识别的命名值:'env'”错误。
Basically, I want to define variables that are valid for all jobs of a workflow but not in other workflows.
基本上,我希望定义适用于工作流的所有作业但不适用于其他工作流的变量。
英文:
With a job
defined by uses
keyword.
Is it possible to use workflow defined env
context ?
If not, is there anyway to define variables in one place or pass context to share workflow env context without having to repeat variables jobs
?
Sample:
name: Build and Publish Helm charts
on:
push:
branches:
- "main"
env:
FOO: BAR
jobs:
test:
uses: '.github/workflows/test.yaml'
with:
FOO: ${{ env.FOO }}
While I would expect test.yaml
to take BAR
in the FOO
input,
testing above scripts throws an Unrecognized named-value: 'env'
error.
Basically, I want to define variables that are valid for all jobs of a workflow but not in other workflows.
答案1
得分: 2
根据限制,由于您正在使用可重用工作流程,环境变量不会传播:
- 在调用工作流程中由调用者工作流程中定义的
env
上下文设置的任何环境变量都不会传播。...
或者:
- 要在多个工作流程中重用变量,请在组织、存储库或环境级别设置它们,并使用
vars
上下文引用它们。
英文:
As you're using reusable workflows, according to its Limitations the env vars are not propagated:
> - Any environment variables set in an env
context defined at the workflow level in the caller workflow are not propagated to the called workflow. ...
Alternatively:
> - To reuse variables in multiple workflows, set them at the organization, repository, or environment levels and reference them using the vars
context. ...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论