I’m trying to call a reusable workflow from another one, passing it some input variables. In the caller workflow I have some environment variables that I want to pass as input to the reusable one, like so:
env:
SOME_VAR: bla_bla_bla
ANOTHER_VAR: stuff_stuff
jobs:
print:
runs-on: ubuntu-latest
steps:
- name: Print inputs passed to the reusable workflow
run: |
echo "some var: $SOME_VAR"
echo "another var: $ANOTHER_VAR"
call_reusable:
uses: ...
with:
input_var: $SOME_VAR
another_input_var: $ANOTHER_VAR
the reusable workflow:
on:
workflow_dispatch:
workflow_call:
inputs:
input_var:
required: true
type: string
another_input_var:
required: true
type: string
jobs:
the_job:
runs-on: ubuntu-latest
steps:
- name: Print inputs
run: |
echo "input_var: ${{ inputs.input_var }}"
echo "another_input_var: ${{ inputs.another_input_var }}"
The Print inputs passed to the reusable workflow
step works fine – all variables are correctly printed. However, the Print inputs
step in the reusable workflow (the callee) does not work as expected – all the variables are empty.
I couldn’t find anything in the docs suggesting that there is something wrong with my approach so, the way I see it, this should be working. Still, looking at the logs there is something wrong, as in the reusable workflow (callee) I can see:
Run echo "input_var: $SOME_VAR"
echo "another_input_var: $ANOTHER_VAR"
shell: /usr/bin/bash -e {0}
input_var:
another_input_var:
I tried wrapping the values in the with:
block in $(echo)
but that didn’t work.
Any ideas?
2
Answers
After some researches, I found this thread explaining that:
Moreover, on the official documentation, it is stated that:
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:
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.
The use of
::set-output
is now deprecated.See https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/.
Now recommended: