Azure-pipelines-tasks: Cancel build from a task

Created on 29 Jul 2016  ·  7Comments  ·  Source: microsoft/azure-pipelines-tasks

Hello,

I have a TFS Project that uses only 1 git repository for multiple projects.
We would like to use continuous integration triggering system but we cannot use path conditionals (which are not available for on premises TFS 2015 if I understood correctly).
Since any push in any repository launch the builds of all the projects, I would like to develop a task that cancel the build depending on the updated files path or the author of the push.

But is there a way to cancel the build process from a task ?

If not I may use a git push event service hook and the REST API to launch the build..

Most helpful comment

We fixed the problem for TFS-2017 on-premise with the agent 2...

We add the following text to the task:
Write-Host "##vso[task.setvariable variable=agent.jobstatus;]canceled"
Write-Host "##vso[task.complete result=Canceled;]DONE"

And the task and build were canceled.

All 7 comments

Vsts online has that feature now. TFS.vnext which is coming soon in rc1 has that feature

No you cannot cancel a build from a task

We fixed the problem for TFS-2017 on-premise with the agent 2...

We add the following text to the task:
Write-Host "##vso[task.setvariable variable=agent.jobstatus;]canceled"
Write-Host "##vso[task.complete result=Canceled;]DONE"

And the task and build were canceled.

Thanks for your answer Peter, that's very useful.

How to Cancel the task and make build also Cancel so that it does not move to next stage?

We fixed the problem for TFS-2017 on-premise with the agent 2...

We add the following text to the task:
Write-Host "##vso[task.setvariable variable=agent.jobstatus;]canceled"
Write-Host "##vso[task.complete result=Canceled;]DONE"

And the task and build were canceled.

I tried this one, but I've got this message:

##[warning]Overwriting readonly task variable 'agent.jobstatus'. This behavior will be disabled in the future. See https://github.com/microsoft/azure-pipelines-yaml/blob/master/design/readonly-variables.md for details.

It's getting error now.

image

Unable to process command '##vso[task.setvariable variable=agent.jobstatus;]canceled' successfully. Please reference documentation (http://go.microsoft.com/fwlink/?LinkId=817296)
Overwriting readonly variable 'agent.jobstatus' is not permitted. See https://github.com/microsoft/azure-pipelines-yaml/blob/master/design/readonly-variables.md for details.

I've just posted a new article shows how to deal with this issue. (In Chinese)

如何有條件的控制 Azure Pipelines 的執行流程

Was this page helpful?
0 / 5 - 0 ratings