Search code examples
github-actions

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.


Solution

  • 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.