Can you control how the tasks are executed in Azure Pipelines?

Viewed 269

I have built a pipeline with 4 tasks

  • Task 1 Builds a VM
  • Task 2 Add a Data Disk
  • Task 3 Add a Second Data Disk
  • Task 4 Add a Third Data Disk

However, if I only want Task 1 and Task 2 to execute how can I skip Task 3 and 4? For example, if the user only wants 1 Data Disk. I know they can be disabled manually but is there a way to automate this based on a variable?

1 Answers

Every stage, job and task has a condition property. You can use a condition expression to decide which tasks to run and when. You can reference variables in such expressions. By promoting these variables to a "Queue time variable" you can let a user control these.

Make sure you prepend each condition with succeeded() to make the previous steps have completed succesfully.

condition: and(succeeded(), gt(variables.Disks, 2))

See:

Related