如何在 yaml 中处理 Azure DevOps 管道中的错误?
How to handle errors in Azure DevOps pipelines in yaml?
在 Azure DevOps 中,我在 yaml 文件中有一些管道在 Terraform 和 Powershell 中执行任务以在 Azure 中部署基础结构。
如果部署期间出现错误,我想触发默认操作(例如打印默认错误消息或删除某些内容等),无论错误是来自 Terraform 脚本还是 Powershell。
我认为 Yaml 文件可以处理此操作,但是如何处理?
您可以通过在部署作业的末尾添加一个具有特殊条件的任务来确保它仅在管道失败时运行; the docs explain the use of these kinds of condition:
You can specify conditions under which a step, job, or stage will run.
- Only when all previous dependencies with the same agent pool have succeeded. If you have different agent pools, those stages or jobs
will run concurrently. This is the default if there is not a condition
set in the YAML.
- Even if a previous dependency has failed, unless the run was canceled. Use
succeededOrFailed()
in the YAML for this condition.
- Even if a previous dependency has failed, even if the run was canceled. Use
always()
in the YAML for this condition.
- Only when a previous dependency has failed. Use
failed()
in the YAML for this condition.
在 Azure DevOps 中,我在 yaml 文件中有一些管道在 Terraform 和 Powershell 中执行任务以在 Azure 中部署基础结构。
如果部署期间出现错误,我想触发默认操作(例如打印默认错误消息或删除某些内容等),无论错误是来自 Terraform 脚本还是 Powershell。
我认为 Yaml 文件可以处理此操作,但是如何处理?
您可以通过在部署作业的末尾添加一个具有特殊条件的任务来确保它仅在管道失败时运行; the docs explain the use of these kinds of condition:
You can specify conditions under which a step, job, or stage will run.
- Only when all previous dependencies with the same agent pool have succeeded. If you have different agent pools, those stages or jobs will run concurrently. This is the default if there is not a condition set in the YAML.
- Even if a previous dependency has failed, unless the run was canceled. Use
succeededOrFailed()
in the YAML for this condition.- Even if a previous dependency has failed, even if the run was canceled. Use
always()
in the YAML for this condition.- Only when a previous dependency has failed. Use
failed()
in the YAML for this condition.