From 205605ffb58f60ce1966f1b16b5c7fdc57bd2ec4 Mon Sep 17 00:00:00 2001 From: Raju RH Date: Tue, 11 Oct 2022 08:54:38 +1300 Subject: [PATCH] Create variables-and-context.yml --- .github/workflows/variables-and-context.yml | 78 +++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/variables-and-context.yml diff --git a/.github/workflows/variables-and-context.yml b/.github/workflows/variables-and-context.yml new file mode 100644 index 0000000..5663bb1 --- /dev/null +++ b/.github/workflows/variables-and-context.yml @@ -0,0 +1,78 @@ +# 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" + + - name: Step 2 + id: step2 + run: echo "::set-output name=step2value::world" + + 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