Bandara
Bandara

Reputation: 800

How to fail a VSTS build task without throwing an exception

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

Answers (1)

Eddie Chen - MSFT
Eddie Chen - MSFT

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

Related Questions