1
votes

I'm writing a multi-stage job in Azure Pipelines that involves generating a matrix from a script as an output of a stage. I want to use that matrix across multiple stages to generate jobs, but I want to use conditions on jobs from a previous stage using that matrix.

Example azure-pipelines.yml:

stages:
- stage: A
  jobs: 
   - job: generateMatrix
- stage: B
  dependsOn: A
  jobs:
    - job: "" # This lets the job name be just the name of the matrix key
      continueOnError: true # steps in these jobs may or may not fail
      strategy:
        matrix: $[ stageDependencies.A.generateMatrix.outputs['matrix'] ]
- stage: C
  dependsOn: # Needs A's matrix and B job results
    - A
    - B
  jobs: 
    - job: "" # The job name here should be the same as in stage B
      continueOnError: true 
      strategy:
        matrix: $[ stageDependencies.A.generateMatrix.outputs['matrix'] ]
      steps:
        - script: echo "Job from Stage B Succeeded"
          condition: eq(stageDependencies.B.variables['Agent.JobName'].result, 'Succeeded')
        - script: echo "Job from Stage B Failed"
          condition: condition: ne(stageDependencies.B.variables['Agent.JobName'].result, 'Succeeded')

So I need to be able one of the following:

  • Be able to parameterize the json path inside the stage dependencies
  • Be able to edit and add a variable to the existing matrix in Stage (B) and somehow output that.

Does anyone have any idea on how to do this? I tried the above but it failed.

1
Do you mean you want to modify the matrix value from stage B in stage C?Cece Dong - MSFT
I want Stage B to modify the matrix outputted in stage A and then have C read that matrix. Essentially the matrix outputted at stage A looks like json { "foo": {"var1": "val1"}, ... } and I want to add another value into that matrix such that json { "foo": {"var1": "val1", "var2": "val2"}, ... } user105189
I could also see this being sovled by having a "collect" job as a second Job in stage B that could rewrite the matrix with the updated values, so long as the matrixed job could output vars that would be readable by the "collect" jobuser105189
You could Accept my reply as an Answer or add a new reply and accept it, this can be beneficial to other community members reading this thread.Cece Dong - MSFT

1 Answers

0
votes

I'm afraid we can not modify the matrix output from Stage A in Stage B. You need to define a new output in Stage B and then use in Stage C.