Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In my Azure DevOps YAML Pipeline, how do I turn a bunch of Stages into a matrix of Jobs?

I have a set of working stages that look something like this.

- stage: UpdateWoW
  dependsOn: Install
  variables:
  - group: ${{ parameters.StageVars }}
  jobs:
  - template: UpdateApp.yml
    parameters:
      AppName: WoW
      Project: oxygen

- stage: UpdateSCII
  dependsOn: Install
  variables:
  - group: ${{ parameters.StageVars }}
  jobs:
  - template: UpdateApp.yml
    parameters:
      AppName: SCII
      Project: carbon

- stage: UpdateDIII
  dependsOn: Install
  variables:
  - group: ${{ parameters.StageVars }}
  jobs:
  - template: UpdateApp.yml
    parameters:
      AppName: DIII
      Project: xenon

Where I am simply calling the same template with two varying parameters. I want to clean this up with a matrix. The documented example doesn't give me much to go on when a template is involved. I have tried a few variants, but so far wherever I inject matrix or include strategy is "unexpected".

- stage: UpdateApps
  dependsOn: Install
  variables:
  - group: ${{ parameters.StageVars }}
  jobs:
  - template: UpdateApp.yml
    matrix:
      wow:
        AppName: WoW
        Project: oxygen

      sc2:
        AppName: SCII
        Project: carbon

      d3:
        AppName: DIII
        Project: xenon

    parameters:
      AppName: $(AppName)
      Project: $(Project)

The called template looks like this:

#UpdateApp.yml
parameters:
  AppName: $(AppName)
  Project: $(Project)

jobs:
- job:
  timeoutInMinutes: 120
  variables:
    Path: D:\games
  steps:
  - template: prep.yml $(Path) 

  - script: dostuff.cmd $(Path) ${{parameters.AppName}} ${{parameters.Project}}

  - script: domore.cmd $(Path) ${{parameters.AppName}} ${{parameters.Project}}
like image 819
B.McKee Avatar asked Oct 28 '22 07:10

B.McKee


1 Answers

Figured it out. Matrix comes in at the job level. The stage looks like this:

- stage: UpdateApps
  dependsOn: Install
  variables:
  - group: ${{ parameters.StageVars }}
  jobs:
  - template: UpdateApp.yml

The template:

#UpdateApp.yml

jobs:
- job:
  timeoutInMinutes: 120
  variables:
    Path: D:\games
  strategy:
    matrix:
      wow:
        AppName: WoW
        Project: oxygen

      sc2:
        AppName: SCII
        Project: carbon

      d3:
        AppName: DIII
        Project: xenon

  steps:
  - template: prep.yml $(Path) 

  - script: dostuff.cmd $(Path) $(AppName) $(Project)

  - script: domore.cmd $(Path) $(AppName) $(Project)
like image 168
B.McKee Avatar answered Jan 02 '23 20:01

B.McKee