如何在主流程中使用可重复使用工作流程中的环境?

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

How to use env from reusable workflow in main pipeline?

问题

I have a reusable workflow where I have sent one value via env like below:

- name: 'reusable_workflow'
  run : |
        echo "value=$variable_name" >> $GITHUB_ENV

Now, I need to use the same value in my main pipeline. How can I achieve this?

Below is the main pipeline where I need to use value:

- name: 'main_pipeline'
  run: |
        echo "${{ env.value }}"

Both are the separate workflows and repos are different.

英文:

I have a reusable workflow where I have sent one value via env like below:

- name: 'reusable_workflow'
  run : |
        echo "value=$variable_name" >> $GITHUB_ENV

Now, I need to use the same value in my main pipeline. How can I achieve this?

Below is the main pipeline where I need to use value:

- name: 'main_pipeline'
  run: |
        echo "${{ env.value }}"

Both are the separate workflows and repos are different.

答案1

得分: 1

根据限制重用工作流

> 在调用者工作流程中定义的env上下文中设置的任何环境变量不会传播到被调用的工作流程。

> 同样,在被调用的工作流程中定义的env上下文中设置的环境变量不可在调用者工作流程的env上下文中访问。相反,您必须使用可重用工作流程的输出

> 可重用工作流程直接在作业中调用,而不是在作业步骤中调用。因此,您不能使用GITHUB_ENV将值传递给调用者工作流程中的作业步骤。

请参阅使用可重用工作流程的输出以共享可重用工作流程的值。

英文:

According to the Limitations of Reusing workflows:

> Any environment variables set in an env context defined at the workflow level in the caller workflow are not propagated to the called workflow.

and,

> Similarly, environment variables set in the env context, defined in the called workflow, are not accessible in the env context of the caller workflow. Instead, you must use outputs of the reusable workflow.

also,

> Reusable workflows are called directly within a job, and not from within a job step. You cannot, therefore, use GITHUB_ENV to pass values to job steps in the caller workflow.

See Using outputs from a reusable workflow to share values from the reusable workflow.

huangapple
  • 本文由 发表于 2023年5月18日 00:51:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76274456.html
匿名

发表评论

匿名网友

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

确定