-
Notifications
You must be signed in to change notification settings - Fork 102
40 lines (37 loc) · 1.14 KB
/
workflow-tester18.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: Test 18 #https://stackoverflow.com/questions/70326569/github-workflow-how-to-conditionally-setup-env-for-all-subsequent-jobs
on:
workflow_dispatch:
push:
jobs:
setup-job:
runs-on: ubuntu-latest
outputs:
var1: ${{ steps.set-variable.outputs.test }}
steps:
- uses: actions/checkout@v2
- name: Set test variable
id: set-variable
run: |
if [ ${{ github.ref }} != 'refs/heads/main' ]; then
echo "IS NOT main branch"
echo "test=abc" >> $GITHUB_ENV
echo "::set-output name=test::abc"
else
echo "IS main branch"
echo "test=123" >> $GITHUB_ENV
echo "::set-output name=test::123"
fi
shell: bash
- name: Read exported variable
run: |
echo "ENV: ${{ env.test }}"
echo "OUTPUT: ${{ steps.check.test-env.test }}"
subsequent-job:
runs-on: ubuntu-latest
needs: [setup-job]
steps:
- uses: actions/checkout@v2
- name: Read exported variable
run: |
echo "ENV: ${{ env.test }}"
echo "OUTPUT: ${{needs.setup-job.outputs.var1}}"