Skip to content

Commit 35a6681

Browse files
Create variables-and-context.yml
1 parent 9f3df5a commit 35a6681

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# I am a workflow that demonstrates how to output the different context objects
2+
3+
name: Variables and Context
4+
5+
# Controls when the action will run. Workflow runs when manually triggered using the UI
6+
# or API.
7+
on:
8+
workflow_dispatch:
9+
# Inputs the workflow accepts.
10+
inputs:
11+
name:
12+
# Friendly description to be shown in the UI instead of 'name'
13+
description: 'Person to greet'
14+
# Default value if no value is explicitly provided
15+
default: 'World'
16+
# Input has to be provided for the workflow to run
17+
required: true
18+
19+
env:
20+
VAR1: myworkflowvar1
21+
VAR2: myworkflowvar2
22+
VAR3: myworkflowvar3
23+
24+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
25+
jobs:
26+
27+
job1:
28+
runs-on: ubuntu-latest
29+
30+
# Steps represent a sequence of tasks that will be executed as part of the job
31+
steps:
32+
- name: Dump GitHub context
33+
env:
34+
GITHUB_CONTEXT: ${{ toJSON(github) }}
35+
run: echo "$GITHUB_CONTEXT"
36+
37+
#step/job output variables
38+
job2:
39+
runs-on: ubuntu-latest
40+
41+
outputs:
42+
output1: ${{ steps.step1.outputs.step1value }}
43+
output2: ${{ steps.step2.outputs.step2value }}
44+
45+
steps:
46+
- name: Step 1
47+
id: step1
48+
# run: echo "::set-output name=step1value::hello"
49+
run: echo "step1value=hello" >> $GITHUB_OUTPUT
50+
51+
- name: Step 2
52+
id: step2
53+
# run: echo "::set-output name=step2value::world"
54+
run: echo "step2value=world" >> $GITHUB_OUTPUT
55+
56+
job3:
57+
runs-on: ubuntu-latest
58+
needs: job2
59+
steps:
60+
- run: echo ${{needs.job2.outputs.output1}} ${{needs.job2.outputs.output2}}
61+
62+
# access/set env variables
63+
job4:
64+
runs-on: ubuntu-latest
65+
env:
66+
VAR2: myjobvar2
67+
VAR3: myjobvar3
68+
steps:
69+
70+
- run: |
71+
echo $VAR1
72+
echo ${{env.VAR1}}
73+
74+
echo ""
75+
76+
echo $VAR2
77+
78+
echo $VAR3
79+
env:
80+
VAR3: mystepvar3

0 commit comments

Comments
 (0)