天青管道-如何根据条件任务结果中断/取消发布 [英] azure pipelines - how to break / cancel a release based on a conditional task result

本文介绍了天青管道-如何根据条件任务结果中断/取消发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由CI触发的发布管道,我想在其中推送新版本的nuget软件包,如果该版本尚不存在.

I have a release pipeline which is triggered by CI where I want to push a new version of a nuget package if that version does not exist yet.

为此,我有一个简单的命令行任务,该任务检查nuget.org上是否存在该nuget并将结果存储在环境变量中.

For that I have a simple command line task which checks whether that nuget is present on nuget.org and stores the result in an environment variable.

然后我可以为后续步骤设置条件,该条件仅在该值变量为true时才执行该步骤.

I can then set the condition for next steps which will only execute the step if that value variable is true.

这一切正常,但是我想知道如何简单地停止发布过程并跳过所有随后的步骤,而又不一一设置其条件.

This works all fine, however I wonder how can I simply stop the release process and skip all subsequent steps, without setting their condition one by one.

此外,如何通过任务将构建状态设置为已取消"?

推荐答案

您可以使用PowerShell任务取消当前的Build或Release:

You can cancel current Build or Release with a PowerShell task:

Write-Host "##vso[task.setvariable variable=agent.jobstatus;]canceled"
Write-Host "##vso[task.complete result=Canceled;]DONE"

因此,在发布管道中添加具有以上代码的Powershell任务,并在自定义条件下将其配置为仅在您不想上传NuGet时才运行,此任务之后的所有任务都将被取消.

So in the release pipeline add a Powershell task with the above code and in the custom condition configure it to run only if you don't want to upload the NuGet, after this task all the tasks after it will be canceled.

PS -状态将为成功",但实际上构建/发布将被取消.

PS - The status will be "Succeeded" but in fact the Build/Release will be canceled.

如果您必须要看到状态已取消",则需要使用Rest API,请检查

If you want must to see the status "Canceled" you need to use Rest API, check this PowerShell script.

这篇关于天青管道-如何根据条件任务结果中断/取消发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆