-
Notifications
You must be signed in to change notification settings - Fork 1
Branch Based Workflow Execution
olsido edited this page Aug 5, 2024
·
1 revision
Running workflows based on specific branches is useful for branch-specific operations, such as deployments to different environments or running different tests based on the branch.
We will create one workflow for the ‘develop’ branch and another workflow for the ‘master’ branch. The final workflow will run only if the previous workflow ran on the ‘develop’ branch.
name: Branch Based Workflow Execution - Develop # Name of the workflow
on:
push: # Trigger this workflow on push events
branches:
- develop # Only trigger on pushes to the develop branch
jobs:
develop-job: # Job name
runs-on: ubuntu-latest # Use the latest Ubuntu runner
steps:
- name: Echo Develop Branch # Step to echo a message
run: echo "This workflow runs on the develop branch." # Print a message indicating the branchView on Gist View in this repo
name: Branch Based Workflow Execution - Final # Name of the workflow
on:
workflow_run: # Trigger this workflow based on the completion of another workflow
workflows: ["Branch Based Workflow Execution - Develop", "Branch Based Workflow Execution - Master"] # List of workflows to monitor
types: [completed] # Trigger on completion of the monitored workflows
branches:
- develop # Only trigger if the monitored workflow ran on the develop branch
jobs:
final-job: # Job name
runs-on: ubuntu-latest # Use the latest Ubuntu runner
steps:
- name: Echo Final Step # Step to echo a message
run: echo "The previous workflow ran on the develop branch." # Print a message indicating the monitored workflow ran on the develop branchView on Gist View in this repo
name: Branch Based Workflow Execution - Final # Name of the workflow
on:
workflow_run: # Trigger this workflow based on the completion of another workflow
workflows: ["Branch Based Workflow Execution - Develop", "Branch Based Workflow Execution - Master"] # List of workflows to monitor
types: [completed] # Trigger on completion of the monitored workflows
branches:
- develop # Only trigger if the monitored workflow ran on the develop branch
jobs:
final-job: # Job name
runs-on: ubuntu-latest # Use the latest Ubuntu runner
steps:
- name: Echo Final Step # Step to echo a message
run: echo "The previous workflow ran on the develop branch." # Print a message indicating the monitored workflow ran on the develop branchView on Gist View in this repo
This setup ensures that workflows run based on the branch they are associated with. The final workflow only runs if the previous workflows ran on the ‘develop’ branch, demonstrating branch-specific workflow dependencies.