skip to Main Content

I have a pipeline that we trigger from the web interface when we want to create a release and it looks something like this:

parameters:
  - name: release
    displayName: Release
    type: string
    default: No
    values:
      - No
      - Dev
      - Prod

trigger: none # will disable CI builds entirely

pool:
  vmImage: "ubuntu-latest"

variables:
  - template: pipelines/variables/flutter_variables.yaml
  - template: pipelines/variables/android_variables.yaml
    parameters:
      releaseMode: ${{ parameters.release }}
  - template: pipelines/variables/ios_variables.yaml
    parameters:
      releaseMode: ${{ parameters.release }

stages:
  ...

Upon completion of this pipeline I want to trigger another run of the the pipeline, but only if the parameter release is set to Prod and the second run of the pipeline should run with that parameter set to Dev.

Is it possible to do this with yaml, or does one have to use a script using az as the last step of the pipeline, and in that case what would that script look like?

2

Answers


  1. Chosen as BEST ANSWER

    We used the following stage as our last step to trigger the rebuild with a different parameter:

        - ${{ if eq(parameters.release, 'Prod') }}:
          - stage: TriggerDevBuild
            condition: succeeded()
            dependsOn:
              - ...
            jobs:
              - job:
                pool:
                  vmImage: "ubuntu-latest"
                steps:
                  - bash: |
                      az pipelines build queue --definition-id <your pipeline definition id> --variables release=Dev
                    displayName: 'Trigger dev build after prod build'
                    env:
                      AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
    

    It only triggers when the current pipeline is running with the release parameter set to Prod and when the other stages have succeeded.


  2. Instead of using az pipeline build queue command use the az pipelines run, in this command you can specify the pipeline parameter

    az pipelines run --id $(System.DefinitionId) --parameters "release=Dev"
    

    The following is the working example:

    parameters:
      - name: release
        displayName: Release
        type: string
        default: No
        values:
          - No
          - Dev
          - Prod
    
    trigger: none
    
    pool:
      vmImage: ubuntu-latest
    
    stages:
    - stage: EmptyStage
      jobs:
      - job: EmptyJob
        steps:
        - script: echo "Default job"
    - ${{ if eq(parameters.release, 'Prod') }}:
      - stage: TriggerDevBuild
        jobs:
          - job:
            pool:
              vmImage: "ubuntu-latest"
            steps:
              - bash: |
                  az pipelines run --id $(System.DefinitionId) --parameters "release=Dev"
                displayName: 'Trigger dev build after prod build'
                env:
                  AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
    

    NOTE: in order for your pipeline to run another pipeline you need to assign the queue builds permission to the ADO Project Build Service user.

    Verification:
    Run the pipeline with the Release parameter set to Prod.
    Results:
    Both stages will be executed in the pipeline, after successful pipeline execution another pipeline run will be queued with the Release parameter set to Dev and only one EmptyStage will be started in the second run.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search