Git & GitHub Interview Question #99

What does the needs keyword do in GitHub Actions?

GitHub Collaboration, Repository Rules, Issues, Releases & Actions CI/CD Mid-Level Intermediate

Quick Interview Answer

The needs keyword creates a dependency between jobs. A dependent job waits for the required job or jobs and normally runs only when the required jobs complete successfully, subject to workflow expressions and conditions.

Detailed Explanation

The needs keyword creates a dependency between jobs. A dependent job waits for the required job or jobs and normally runs only when the required jobs complete successfully, subject to workflow expressions and conditions.

This is useful for pipelines such as build, test, package, and deploy where later stages must not begin before earlier validation succeeds.

Code Example

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Build"

  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - run: echo "Deploy"