skip to Main Content

Background

As I understand it, when creating a release pipeline in classic mode in Azure DevOps, you are provided the option to run your job with the Parallelism Execution plan. Once you select that plan, you can provide a Multipliers variable(s) that will run your job once for every multiplier variable you provide, switching out the variable value for every value in your comma separated string.

So for example, if I created the following release pipeline job:

enter image description here

And provided the following pipeline variable:
TenantName: Tenant001, Tenant002, Tenant003 

My pipeline would be run 3 times – once for each variable value.

Question

Is it possible to do the same thing with yml for a build pipeline?

The closes thing I found is the parallel job strategy but that provides no option for a Multiplier variable.

2

Answers


  1. Chosen as BEST ANSWER

    Upon further investigation, I think I found the answer.

    We can use the matrix strategy combined with some simple logic to expand a pipeline variable into multiple values via bash.

    enter image description here


  2. Another option to run multiple jobs in parallel would be to use the each keyword to loop through parameters and generate a job for each option.

    Example:

    parameters:
      - name: tenants
        type: object
        default:
          - Tenant1
          - Tenant2
          - Tenant3
    
    trigger: none
    
    pool:
      vmImage: 'ubuntu-latest'
    
    jobs:
      - ${{ each tenant in parameters.tenants }}:
        - job: job_${{ tenant }}
          dependsOn: [] # no dependencies, run jobs in parallel
          displayName: Hello ${{ tenant }}
          steps:
          - script: |
              echo "Hello, ${{ tenant }}!"
            displayName: "Hello ${{ tenant }}"
    

    Running the build:

    Build logs

    Note:

    • The disadvantage of this approach is that there is no way to restrict the maximum number of jobs that can run in parallel, as opposed to the matrix strategy (using the maxParallel property).
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search