GitHub Actions · Lesson 3 of 10 · 3 min read
Jobs: dependencies, matrices, conditions and services
Dependencies and outputs
jobs:
build:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.meta.outputs.tag }}
steps:
- id: meta
run: echo "tag=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
deploy:
needs: build # runs after build succeeds
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- run: echo "Deploying ${{ needs.build.outputs.tag }}"
needs builds a DAG; if: always() or if: failure() on a dependent job runs it regardless or only on failure (e.g. notifications).
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Matrix builds
strategy:
fail-fast: false # let other combinations finish
max-parallel: 4
matrix:
java: [17, 21]
os: [ubuntu-latest, windows-latest]
include:
- java: 21
os: ubuntu-latest
coverage: true
exclude:
- java: 17
os: windows-latest
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Conditions, timeouts and resilience
if:on jobs and steps:if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v').timeout-minuteson jobs (default 360 minutes) — set it; hung jobs burn minutes.continue-on-error: truefor optional steps (e.g. an experimental linter).- Re-run failed jobs from the UI; there's no built-in step retry — use a retry action or a shell loop for flaky network calls.
Service containers and container jobs
jobs:
integration:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env: { POSTGRES_PASSWORD: test }
ports: ["5432:5432"]
options: >-
--health-cmd "pg_isready" --health-interval 5s --health-retries 10
steps:
- uses: actions/checkout@v4
- run: ./gradlew integrationTest
env: { DB_URL: "jdbc:postgresql://localhost:5432/postgres" }
container: runs the whole job inside a container image (consistent toolchain).
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.