Reputation: 1420
Does Azure DevOps pipeline supports only re-running a failed task and not the entire stage?
For example we have the deploy to test environment stage which is composed from multiple tasks.
To simplify the description let's assume there are only 2 tasks: first task to execute some SQL statements and the second to execute some UNIX scripts.
I don't want to re-run the SQL task if the UNIX one fails.
Upvotes: 2
Views: 6945
Reputation: 35624
Does Azure DevOps pipeline supports only re-running a failed task and not the entire stage?
I am afraid that there is no out-of-box method could meet your requirements.
For a workaround:
You could try to use the variable: SYSTEM.STAGEATTEMPT in task condition. This variable is used for recording the number of stages runs.
Here is an example:
stages:
- stage: QA
jobs:
- job: test
steps:
- task: PowerShell@2
condition: eq(variables['SYSTEM.STAGEATTEMPT'], '1')
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
Write-Host "Hello World"
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
xxxx
Result:
You could set this condition for the SQL Task, then the task will only run for the first stage run.
When you re-run the failed stage, the SQL Task will skip.
On the other hand, you requirement makes sense.
Here is the suggestion ticket in our UserVoice Site: Rerun failed build task/step.
Upvotes: 4
Reputation: 1016
Unfortunately there isn't a way to re-run only the task, however there is a solution (workaround) for your scenario, instead of building this particular stage of your pipeline with many steps within a job, you can split your SQL task and Unix task in two different jobs, and make them dependent, thus if one fails, it won't execute another here's an example:
...
jobs:
- job: SQLJob
steps:
- task: RunSomeSQLScripts
- job: UnixJob
dependsOn:
- SQLJob
steps:
- task: RunSomeUnixScripts
...
In case you need to share files between jobs you can publish them as artifacts, in case you need to generate some variables in the previous jobs and use in the second one, you can use output variables: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch
Upvotes: 2