Friday, December 20, 2024

Working with Unskippable Stages in Azure DevOps

Azure DevOps pipelines have several stages, and we can use these stages to fulfill various specific automation requirements. However, there can be stages that should not be skipped during the deployment process for any reason. For example, some organizations may have a policy that it is mandatory to run automated tests before deployment, or it is mandatory to run a security scan stage. By default, Azure DevOps allows its users to skip stages when initiating a new pipeline run. Now, Azure DevOps has introduced a new property that can be used with YAML pipelines to disable the option to skip stages during the pipeline creation.

Pre-requisites:

Azure DevOps YAML pipeline with multiple stages

When triggering a new pipeline run, go to the Stages to run section.


It is possible to skip stages from Stages to run section, before Run the pipeline.




Now, let's add the new property isSkippable: false to the pipeline stage to create an unskippable stage.

ex:
stageStageB
  displayNameStageB
  dependsOnStageA
  isSkippablefalse
  jobs:
  - jobJobA
    steps:
      - powershellWrite-Host "This is Job A"
        namecheckCondition
  - jobJobB
    steps:
    - powershell:  Write-Host "This is Job B"


Now that we have added an unskippable stage to the YAML script, let's run the pipeline again.

Go to Stages to Run section. StageB is marked as an unskippable stage, as shown in the image below.



Following is the sample pipeline script with the unskippable stage.


trigger:
  branches:
    include:
      - develop

pool: 
  name: "Azure Pipelines"

  
stages:
- stage: StageA
  jobs:
  - job: JobA
    steps:
      - powershell: Write-Host "This is Job A"
        name: checkCondition
  - job: JobB
    condition: in(dependencies.JobA.result, 'skipped')
    steps:
    - powershell:  Write-Host "This is Job B"      

- stage: StageB
  displayName: StageB
  dependsOn: StageA
  isSkippable: false
  jobs:
  - job: JobA
    steps:
      - powershell: Write-Host "This is Job A"
        name: checkCondition
  - job: JobB
    steps:
    - powershell:  Write-Host "This is Job B"   

- stage: StageC
  dependsOn: StageB
  jobs:
  - job: JobA
    steps:
      - powershell: Write-Host "This is Job A"
        name: checkCondition
  - job: JobB
    steps:
    - powershell:  Write-Host "This is Job B"  




    








No comments:

Post a Comment