使用作业中定义的环境上下文

huangapple go评论71阅读模式
英文:

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.yamlFOO输入中使用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. ...

huangapple
  • 本文由 发表于 2023年4月13日 23:46:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76007405.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定