Azure Pipelines: Conditional run of task groups

Viewed 3248

In Azure pipelines, I can conditionally run a specific task/job. However, if I have a Task group, I don't see any option to specify conditions on its execution.

The only way am able to do this is to create a new Job altogher which runs the task group and specify the conditinal expression in the Job.

This has drawback - Jobs are run on different agents. In this case, a new agent is created only to run that task group under a condition. This slows down the deployment

So - question is - how to conditinally execute a Task Group?

Thanks

1 Answers

According to the doc: Task conditions (such as "Run this task only when a previous task has failed" for a PowerShell Script task) can be configured in a task group and these settings are persisted with the task group.

If you want to custom task group level condition, It is not supported by azure devops for the time being.

I found a ticket on our UserVoice site , which is our main forum for product suggestions. you can vote and add your comments for this feedback. The product team would provide the updates if they view it.

Update1

As a workaround, We can define these tasks in the yaml template and then we can call different templates from a pipeline YAML depending on a condition.

Sample code:

parameters:
- name: experimentalTemplate
  displayName: 'Use experimental build process?'
  type: boolean
  default: false

steps:
  - ${{ if eq(parameters.experimentalTemplate, true) }}:
    - template: experimental.yml
  - ${{ if not(eq(parameters.experimentalTemplate, true)) }}:
    - template: stable.yml
Related