7
votes

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?

3

3 Answers

4
votes

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..."
15
votes

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.

0
votes

You cannot do that from GUI really. well, you can, you just comment them out with #. in the editor