DevOps / Github Interview questions
How do you write a multi-job GitHub Actions workflow?
A multi-job workflow defines several named entries under jobs, each with its own runs-on runner and steps. Jobs run in parallel unless one declares a needs dependency on another, which forces it to wait until the referenced job succeeds.
name: Build, Test, Deploy on: push: branches: [main] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: docker build -t myapp:${{ github.sha }} . unit-tests: runs-on: ubuntu-latest needs: build steps: - uses: actions/checkout@v4 - run: npm run test:unit lint: runs-on: ubuntu-latest needs: build steps: - uses: actions/checkout@v4 - run: npm run lint deploy: runs-on: ubuntu-latest needs: [unit-tests, lint] environment: staging steps: - run: ./deploy.sh staging
Here, unit-tests and lint both depend on build and run in parallel with each other once it finishes, while deploy waits for both of them before running. The environment: staging key ties the deploy job to a tracked GitHub Environment, enabling deployment history and, on higher plans, required approvers before that job can run.
More Related questions...