Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Azure DevOps is there a GUI way to disable tasks in YAML based pipeline?

Fairly new to Azure DevOps and using it for Infrastructure as Code Azure deployments.
Using Classic release pipelines, you can go into the pipeline, into a Stage and very quickly enable/disable tasks within that Stage

enter image description here

How would you do this with YAML pipelines?

like image 318
Wayno Avatar asked Dec 13 '19 06:12

Wayno


People also ask

How do I disable a task in YAML pipeline?

You can try set variables : enabled = false , then use the variable in YAML file. If set this way, this task will not run in the job.

What is the advantage of defining a pipeline using YAML in Azure DevOps?

Overview. Many teams prefer to define their build and release pipelines using YAML (YAML Ain't Markup Language). This allows them to access the same pipeline features as those using the visual designer, but with a markup file that can be managed like any other source file.

How do I disable classic pipeline in Azure DevOps?

In my case, the pipeline is called Build, and I will click on the pipeline's options and click on Settings on the right corner, as shown in the screenshot below. I will set the “Processing of new run requests” from the options page to disabled.

Does Azure pipelines support coding through YAML?

Azure Pipelines supports continuous integration (CI) and continuous delivery (CD) to continuously test, build, and deploy your code. You accomplish this by defining a pipeline. The latest way to build pipelines is with the YAML pipeline editor. You can also use Classic pipelines with the Classic editor.


2 Answers

In addition to comment out tasks with #, here I provide another workaround :

You can try set variables : enabled = false, then use the variable in YAML file.

steps:
- task: PublishSymbols@2
  displayName: 'Publish symbols path'
  inputs:
    SearchPattern: '**\bin\**\*.pdb'
    PublishSymbols: false
  enabled: false
  continueOnError: true

If set this way, this task will not run in the job.

enter image description here

This method is mentioned in this case, you can refer to it for details.

like image 189
Hugh Lin Avatar answered Sep 22 '22 21:09

Hugh Lin


Now with runtime parameters you have a GUI option. If you de-select the checkbox (see pic below) then you can pass that parameter to the pipeline.

enter image description here

There are [to my knowledge] three methods of implementing the runtime parameter in tasks and you can also apply most of logic in jobs/stages (with the exception that jobs/stages don't [currently] have an 'enabled' property);

parameters:
- name: RunTask
  displayName: Run task?
  type: boolean
  default: true

steps:

- pwsh: Write-Host "always run this task"

- pwsh: Write-Host "skip this task when checkbox unticked..."
  condition: eq(${{ parameters.RunTask }}, true)

- pwsh: Write-Host "skip this task when checkbox unticked..."
  enabled: ${{ parameters.RunTask }}

- ${{ if eq(parameters.RunTask, true) }}:
  - pwsh: Write-Host "skip this task when checkbox unticked..."

- ${{ if parameters.RunTask }}:
  - pwsh: Write-Host "skip this task when checkbox unticked..."
like image 28
alv Avatar answered Sep 18 '22 21:09

alv