Skip to content

Variables and Context #1

Variables and Context

Variables and Context #1

# I am a workflow that demonstrates how to output the different context objects
name: Variables and Context
# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
workflow_dispatch:
# Inputs the workflow accepts.
inputs:
name:
# Friendly description to be shown in the UI instead of 'name'
description: 'Person to greet'
# Default value if no value is explicitly provided
default: 'World'
# Input has to be provided for the workflow to run
required: true
env:
VAR1: myworkflowvar1
VAR2: myworkflowvar2
VAR3: myworkflowvar3
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
job1:
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
#step/job output variables
job2:
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.step1.outputs.step1value }}
output2: ${{ steps.step2.outputs.step2value }}
steps:
- name: Step 1
id: step1
# run: echo "::set-output name=step1value::hello"
run: echo "step1value=hello" >> $GITHUB_OUTPUT
- name: Step 2
id: step2
# run: echo "::set-output name=step2value::world"
run: echo "step2value=world" >> $GITHUB_OUTPUT
job3:
runs-on: ubuntu-latest
needs: job2
steps:
- run: echo ${{needs.job2.outputs.output1}} ${{needs.job2.outputs.output2}}
# access/set env variables
job4:
runs-on: ubuntu-latest
env:
VAR2: myjobvar2
VAR3: myjobvar3
steps:
- run: |
echo $VAR1
echo ${{env.VAR1}}
echo ""
echo $VAR2
echo $VAR3
env:
VAR3: mystepvar3