Quantcast
Viewing all articles
Browse latest Browse all 7

Answer by GuiFalourd for Passing env variable inputs to a reusable workflow

After some researches, I found this thread explaining that:

You can’t pass ENV variables to the reusable workflow, so they are almost useless in this pattern.

Moreover, on the official documentation, it is stated that:

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

Therefore, in your case, you wont be able to achieve what you want using directly the env variable, but there are workarounds.

Note: It would be great if GitHub comes up with a better way to assign values inline or pass them into reusable workflows, as handling each parameter many times just to pass it into a reusable workflow is cumbersome.


A workaround could be to use outputs from a first job, and use those outputs as the reusable workflow inputs.

Here is an example of how it could be done:

env:  SOME_VAR: bla_bla_bla  ANOTHER_VAR: stuff_stuffjobs:  print:    runs-on: ubuntu-latest    outputs:      some_var: ${{ steps.step1.outputs.some_var }}      another_var: ${{ steps.step1.outputs.another_var }}       steps:      - name: Print inputs passed to the reusable workflow        id: step1        run: |          echo "some var: $SOME_VAR"          echo "some_var=$SOME_VAR" >> $GITHUB_OUTPUT          echo "another var: $ANOTHER_VAR"          echo "another_var=$ANOTHER_VAR" >> $GITHUB_OUTPUT  call_reusable:    needs:      - print    uses: ...    with:      input_var: ${{ needs.print.outputs.some_var }}      another_input_var: ${{ needs.print.outputs.another_var }}

EDIT: Removed ::set-output syntax which is now deprecated.

That way, without updating the reusable workflow implementation, the inputs would be filled with the expected values.

Here are the workflow I used to test: main+reusable

And you can check the workflow run with the expected outcome here.


Viewing all articles
Browse latest Browse all 7

Trending Articles