Edit this page
Learn how to pass data between jobs or steps or set conditionals using variables in Workflows.
Variables can be used in workflows to pass data between jobs or steps. They are useful for conditionals on subsequent jobs or affecting the output of a workflow.
You can set variables in the workflow file with the set-output
function:
jobs:
fingerprint:
outputs:
fingerprint_hash_for_workflow: ${{ steps.fingerprint_hash_step.outputs.fingerprint_hash_for_workflow }}
steps:
- uses: eas/checkout
- uses: eas/install_node_modules
- name: Install additional tools
run: sudo apt-get update -y && sudo apt-get install -y jq
- name: Set fingerprint variables
id: fingerprint_hash_step
outputs: [fingerprint_hash_for_workflow, fingerprint_hash_for_steps]
run: |
FINGERPRINT=$(npx expo-updates fingerprint:generate --platform ios)
FINGERPRINT_HASH=$(echo $FINGERPRINT | jq -r '.hash')
echo "Fingerprint hash: $FINGERPRINT_HASH"
set-output fingerprint_hash_for_workflow $FINGERPRINT_HASH
set-output fingerprint_hash_for_steps $FINGERPRINT_HASH
- name: Print fingerprint hash
run: |
echo "Fingerprint hash: ${ steps.fingerprint_hash_step.fingerprint_hash_for_steps }"
existing_build:
needs: [fingerprint]
type: get-build
params:
fingerprint_hash: ${{ needs.fingerprint.outputs.fingerprint_hash_for_workflow }}
decide:
needs: [existing_build]
steps:
- name: decide
run: |
BUILD_ID="${{ needs.existing_build.outputs.build_id || '' }}"
echo $BUILD_ID
if [ -z "${BUILD_ID}" ] ; then
echo "No build found. Should build."
exit 0
fi
echo "Found build: https://expo.dev/uuid/$BUILD_ID"
echo "More about build: ${{ toJSON(needs.existing_build.outputs) }}"
In the example above, three things are happening:
set-output
function sets the fingerprint_hash_for_steps
and fingerprint_hash_for_workflow
variables.outputs
keyword on the step inside the fingerprint
job exposes the fingerprint_hash_for_steps
variable to other steps in fingerprint
job. That variable is used in an echo
statement later in the job.outputs
keyword on the fingerprint_hash_for_workflow
job specifies that the whole workflow will have access to a variable called fingerprint_hash_for_workflow
. That variable is later used in the existing_build
job to check if there are any existing builds with the same fingerprint.