From 0d03a3234e265aa17bcab18a1edc4f4cb513bc9e Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 22 Jan 2025 01:34:43 +0530 Subject: [PATCH] add workflow for chaining jobs in github actions --- .github/context-and-variables.md | 4 +++ .github/workflows/chainingJobs.yml | 48 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/chainingJobs.yml diff --git a/.github/context-and-variables.md b/.github/context-and-variables.md index b31c826..e72c244 100644 --- a/.github/context-and-variables.md +++ b/.github/context-and-variables.md @@ -113,4 +113,8 @@ When accessing a variable, the lookup follows this order: Hence, in the above example, the output is as follows: ```bash +value of VAR1 is myworkflowvar1 +value of VAR1 is myworkflowvar1 +value of VAR2 is myjobvar2 +value of VAR3 is mystepvar3 ``` diff --git a/.github/workflows/chainingJobs.yml b/.github/workflows/chainingJobs.yml new file mode 100644 index 0000000..04d01ac --- /dev/null +++ b/.github/workflows/chainingJobs.yml @@ -0,0 +1,48 @@ +name: Chaining Jobs + +on: + workflow_dispatch: + + inputs: + run-job-3: + description: "Run job 3" + type: boolean + +jobs: + + job-1: + name: Job 1 + runs-on: ubuntu-latest + steps: + - name: Output for Job 1 + run: echo "Hello from Job 1. Run Job 3 equals ${{ github.event.inputs.run-job-3 }}" + + job-2: + name: Job 2 + runs-on: ubuntu-latest + needs: + - job-1 + steps: + - name: Output for Job 2 + run: echo "Hello from Job 2" + + job-3: + name: Job 3 + if: github.event.inputs.run-job-3 == 'true' # if the input is false, this job would be skipped + runs-on: ubuntu-latest + needs: + - job-1 + steps: + - name: Output for Job 3 + run: echo "Hello from Job 3" + + job-4: + name: Job 4 + runs-on: ubuntu-latest + # if: always() # Causes the job to always execute + needs: + - job-2 + - job-3 + steps: + - name: Output for Job 4 + run: echo "Hello from Job 4" \ No newline at end of file