Deduplicating parameters in pipeline job matrix

Hi, I’ve written a pipeline which has sequential jobs using the same matrix expansion.
Is there some way to write the pipeline definition without duplicating this expansion? Here’s my code:

workflows:
  version: 2
  deploy:
    jobs:
      - plan:
          name: Plan << matrix.environment >>
          matrix:
            parameters:
              environment:
                - red
                - blue
                - green
      - apply:
          name: Apply << matrix.environment >>
          requires:
            - Plan << matrix.environment >>
          matrix:
            parameters:
              environment:
                - red
                - blue
                - green

Hi @alexjurkiewicz,

Would YAML anchors work for you in this scenario? I.e. from your example you could do this:

matrix: &matrix
  matrix:
    parameters:
      environment:
        - red
        - blue
        - green

workflows:
  version: 2
  deploy:
    jobs:
      - plan:
          name: Plan << matrix.environment >>
          <<: *matrix
      - apply:
          name: Apply << matrix.environment >>
          requires:
            - Plan << matrix.environment >>
          <<: *matrix

Hope the above helps!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.