Reputation: 486
I am currently writing a pipeline to deploy my infrastructure in Terraform.
I would like that some tasks do not run unless the first task has run successfully. I have found the use of conditions such as success()
or failed()
.
However, upon reading closely, I realize that these conditions are based on Job Status, while in my case there is just one job containing all my tasks.
Is there any way to specify such condition ? And will it be able to refer to a specific task name ? (For example, Task C can run only if Task A ran with success).
Upvotes: 2
Views: 3610
Reputation: 753
You could add a PowerShell task just behind the first task to set a variable (ones for example) by using ##vso[task.setvariable variable=ones]true
. Then, use this variable in condition for those tasks that you want them do not run unless the first task has run successfully.
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
Write-Host "##vso[task.setvariable variable=ones]true"
Then, set condition: condition: eq(variables.ones, 'true')
for each task that you do not want it run unless the first task has run successfully. for example:
- task: PowerShell@2
displayName: task4
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
Write-Host "Hello World"
condition: eq(variables.ones, 'true')
The PowerShell task will run if the previous tasks run successfully, in my case, there only is task1. Thus, if the task1 succeed, PowerShell task will set the variable value as true. Next tasks will run when the variable equal true. When the task1 failed, neither PowerShell task will run nor the next tasks.
Upvotes: 2