Interview Prep/Real-World Interview/Write-a-pipeline tasks

Write a GitHub Actions deploy job that requires approval for production using environments.

BeginnerHands-onWrite-a-pipeline tasks
Answer
jobs:
  deploy-staging:
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - run: ./deploy.sh staging
  deploy-prod:
    needs: deploy-staging
    runs-on: ubuntu-latest
    environment:
      name: production
      url: https://app.example.com
    steps:
      - run: ./deploy.sh production

Key trick → Required reviewers, wait timers and branch restrictions are configured on the production environment in repo settings. The job pauses until someone approves, and environment-scoped secrets are only released then.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-pipeline tasks