Reputation: 800
I need to fail my VSTS build task based on a condition, I'm throwing an error to achieve this from code. This logs an unhanded exception in my build log. Is there a better way of doing this?
if (myCollection.length === 0) {
throw new Error("Build Failed: No data avilable.");
}
Upvotes: 0
Views: 805
Reputation: 29976
You can use setResult() method in vsts-task-lib to pass or fail the build task.
import tl = require('vsts-task-lib/task');
function passorfailtask() {
tl.setResult(tl.TaskResult.Failed, 'Build Failed: No data avilable.');
}
passorfailtask()
Upvotes: 3