Skip to content

Allow dynamic mapping of needs: for parallel matrix jobs

Proposal

Currently, it's not possible to dynamically map the needs: keyword between two dependent jobs that both use parallel:matrix. This limitation makes it difficult to create efficient pipelines with parallel jobs that have specific dependencies on each other. This has been requested by a customer here (internal link)

Consider a scenario where we have two jobs, both using parallel:matrix:

A build job that builds different components of an application. A test job that needs to run tests on these specific components. We want each test job to depend only on its corresponding build job, but the current syntax doesn't allow for this dynamic mapping.

Example of desired functionality:

build:
  parallel:
    matrix:
      - COMPONENT: [A, B, C]
  script:
    - build $COMPONENT

test:
  parallel:
    matrix:
      - COMPONENT: [A, B, C]
  needs:
    - job: build
      matrix:
        COMPONENT: $COMPONENT
  script:
    - test $COMPONENT

Current Limitation: The above YAML is currently invalid because we can't reference $COMPONENT inside the needs: block.

Proposed Solution: Allow referencing of environment variables (like $COMPONENT) inside the needs: block for matrix jobs. This would enable dynamic mapping of dependencies between parallel matrix jobs.

Alternative Solution: If referencing environment variables directly is not feasible, consider introducing a new syntax for matrix job references.