How can I prevent TFS from failing a PowerShell step when an error is written to the error stream? How can I prevent TFS from failing a PowerShell step when an error is written to the error stream? powershell powershell

How can I prevent TFS from failing a PowerShell step when an error is written to the error stream?


You could uncheck the Fail on Standard Error in your PowerShell script configuration and write the lastexitcode to pass the task.

Enter image description here

Fail on Standard Error

If this is true, this task will fail if any errors are written to the error pipeline, or if any data is written to the Standard Error stream. Otherwise the task will rely solely on $LASTEXITCODE and the exit code to determine failure.

Then you can output the error or warning by using PowerShell or VSTS task commands.

Write-Warningwarning”Write-Errorerror”Write-Host " ##vso[task.logissue type=warning;]this is the warning"Write-Host " ##vso[task.logissue type=error;sourcepath=consoleapp/main.cs;linenumber=1;columnnumber=1;code=100;]this is an error "

More information about the VSTS task command, you can refer to: Logging Commands


The following script worked for me in VSTS:

Write-Host "Running build script..."&$CAKE_EXE $cakeArguments 2>&1 | Write-Host

I just added "2>&1 | Write-Host" to the command so that the standard error stream will be routed to the Write-Host stream.