azure pipelines - how to break / cancel a release based on a conditional task result

为君一笑 提交于 2020-07-20 04:12:12

问题


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.

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.

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.

Also, to that, how can I set the build status to 'Cancelled' by a task?


回答1:


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"

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 - The status will be "Succeeded" but in fact the Build/Release will be canceled.

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



来源:https://stackoverflow.com/questions/55891350/azure-pipelines-how-to-break-cancel-a-release-based-on-a-conditional-task-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!