GitHub Actions Certification

GitHub Actions Core Concepts

Workflow with multiple Jobs

In this guide, we’ll transform a simple, single-job GitHub Actions workflow into a robust multi-job CI/CD pipeline. You’ll learn how to split build, test, and deploy stages into separate jobs, ensure proper sequencing, and share artifacts between steps.


Table of Contents

  1. Recap: Single-Job Workflow
  2. Multi-Job Workflow Setup
  3. Default Parallel Execution & Failures
  4. Common Errors
  5. Issues to Address Next
  6. References

Recap: Single-Job Workflow

Our original workflow ran every step in one job:

# .github/workflows/generate-ascii.yml
name: Generate ASCII Artwork
on: push

jobs:
  ascii_job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Execute ASCII script
        run: |
          chmod +x ascii-script.sh
          ./ascii-script.sh

This approach is simple but not scalable. Everything—from installation to deployment—occurs in a single VM instance.


Multi-Job Workflow Setup

Below is an improved workflow with three distinct jobs: build_job_1, test_job_2, and deploy_job_3. Each job runs on its own runner:

# .github/workflows/generate-ascii.yml
name: Generate ASCII Artwork
on:
  push:
    branches:
      - main

jobs:
  build_job_1:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Install cowsay
        run: sudo apt-get update && sudo apt-get install cowsay -y

      - name: Generate ASCII dragon
        run: cowsay -f dragon "Run for cover, I am a DRAGON.... RAWR" >> dragon.txt

      - name: Pause for 30 seconds
        run: sleep 30

  test_job_2:
    runs-on: ubuntu-latest
    steps:
      - name: Pause for 10 seconds
        run: sleep 10

      - name: Verify dragon.txt
        run: grep -i "dragon" dragon.txt

  deploy_job_3:
    runs-on: ubuntu-latest
    steps:
      - name: Display dragon.txt
        run: cat dragon.txt

      - name: Simulate deployment
        run: echo "Deploying dragon.txt..."

Job Overview

Job NamePurposeKey Steps
build_job_1Install dependencies & generateInstall cowsay, create dragon.txt
test_job_2Validate build outputCheck for “dragon” in dragon.txt
deploy_job_3Output & deployPrint file content, simulate deployment

Default Parallel Execution & Failures

By default, GitHub Actions runs jobs in parallel on separate VMs. Since there’s no shared filesystem or enforced order, downstream jobs may start before the build completes.

The image shows a GitHub Actions workflow summary with three jobs: "build_job_1" succeeded, while "test_job_2" and "deploy_job_3" failed, resulting in an overall workflow failure.

Note

Jobs in GitHub Actions are isolated by default. To share files or enforce ordering, you’ll need to use job dependencies and artifacts.


Common Errors

When jobs run in parallel without dependencies, you may see errors like:

grep -i "dragon" dragon.txt
cat dragon.txt
# cat: dragon.txt: No such file or directory
# Error: Process completed with exit code 1.

Issues to Address Next

  1. Job Sequencing
    Ensure build_job_1 completes before test_job_2, and test_job_2 before deploy_job_3 using the needs keyword.

  2. Artifact Sharing
    Use actions/upload-artifact in the build job and actions/download-artifact in downstream jobs to pass dragon.txt.


References

Watch Video

Watch video content

Previous
Executing Shell Scripts in Workflow