Skip to content

CICD-219 · Dynamic job generation ​

Encyclopedia · Advanced workflow orchestration · All snippets

Previous · CICD-218 · Next · CICD-220

1. Where it fits ​

  • Placement Under the jobs map in the matrix workflow.
  • Prerequisites authenticated GitHub CLI, approved target repositories, or Actions runner for YAML entries.
  • Platforms github-actions.
  • Parameters GITHUB_OUTPUT, SERVICE.

2. Copy the snippet ​

yaml
plan:
  runs-on: ubuntu-latest
  outputs:
    targets: ${{ steps.list.outputs.items }}
  steps:
    - id: list
      run: echo 'items=["api","worker"]' >> "$GITHUB_OUTPUT"
build:
  needs: plan
  strategy:
    matrix:
      service: ${{ fromJSON(needs.plan.outputs.targets) }}
  runs-on: ubuntu-latest
  steps:
    - env:
        SERVICE: ${{ matrix.service }}
      run: echo "$SERVICE"

3. How it works ​

The plan job emits a JSON array and exposes it as a job output. The consumer calls fromJSON to generate one service job per entry.

A runtime JSON value creates the service jobs.

flowchart TD
  N1["Planner job"]
  N2["Service JSON output"]
  N1 --> N2
  N3["API job"]
  N2 --> N3
  N4["Worker job"]
  N2 --> N4
  N5["Combined evidence"]
  N3 --> N5
  N4 --> N5

4. Verify the result ​

The planner emits JSON once. The scheduler expands two jobs from the producer output.

Validation syntax-validated (YAML parse). Status definitions.