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..
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.

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)
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.