azure-devopsazure-pipelinespipelineazure-pipelines-yaml

How not to excecute specific Azure Pipeline stage which is defined with a template


I have a Azure pipeline based on templates which are created by another team. I have no EDIT permissions for those templates. One of the stages of the pipeline is:

  - template: oo-templates/d-template.yaml@RepoTemplates
    parameters:
      stage: 'Test_Deployment' 

It is visible when I run the pipeline from the portal: enter image description here

I would like to temporary disable it from the code. I have tried to add condition like this:

  - template: oo-templates/d-template.yaml@RepoTemplates
    parameters:
      stage: 'Test_Deployment' 
      condition: false

but it did not bring any effect. Is there any other flag or any other way to "switch off" given stage? preferably in that way that it will be "disabled" be default in the stages list when running the pipeline.


Solution

  • When you queue a new pipeline, all available stages will be selected in the "Stages to run" section. There is no way to automatically deselect a specific stage.

    You can control which stages are generated when a pipeline starts, though.

    Example

    Consider a simple pipeline with 2 stages - Build and Deploy:

    Pipeline stages

    If you don't want the Deploy stage to run by default you can define a boolean parameter named deployApplication set to false:

    # my-pipeline.yaml
    
    parameters:
      - name: deployApplication
        displayName: 'Deploy Application'
        type: boolean
        default: false # <-------------- Don't deploy by default
    
    stages:
      - template: /pipelines/stages/build-deploy-stages.yaml
        parameters:
          deployApplication: ${{ parameters.deployApplication }}
    

    Stages template:

    parameters:
      - name: deployApplication
        displayName: 'Deploy Application'
        type: boolean
    
    stages:
      - stage: Build
        displayName: Build
        dependsOn: []
        jobs:
          - job: job_Build
            steps:
              - checkout: none
              - script: echo Build
      
      - ${{ if parameters.deployApplication }}: # <--------- generate stage based on parameter
        - stage: Deploy
          displayName: Deploy
          dependsOn: Build
          jobs:
            - job: job_Deploy
              steps:
                - checkout: none
                - script: echo Deploy
    

    Queuing a new pipeline - default values:

    New pipeline - default

    Deploy stage won't be generated so it won't be visible in "Stages to run":

    Stages to run - default

    Selecting "Deploy Application":

    New pipeline - boolean parameter selected

    Deploy stage is now visible in "Stages to run":

    Stages to run - boolean parameter selected