15

I have a PowerShell step in a TFS build that writes an error to the error stream and thus fails the build. I'd like the step to ignore the error and continue on as succeeded.

Process completed with exit code 0 and had 1 error(s) written to the error stream.

I've tried setting the Continue on error option in TFS, but this results in a "build partially succeeded" status, but what I want is for it to be "successful".

I've also tried adding 2>&1 > output.txt to the end of the line that generates the error, but the errors are still written to the TFS output and not captured in the text file.

The command I'm executing is the New-TfsChangeset cmdlet from the TFS 2015 Power Tools.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John Mills
  • 10,020
  • 12
  • 74
  • 121
  • 1
    Hi, I couldn't use your solution nor verify that it works because we're on TFS 2015 for now. I upvoted it however. To work around it, I've disabled check-in policies that were erroring upon check-in with the `New-TfsChangeset` command. The TFS 2015 Powertools has defects in it around the check-in policies. – John Mills Jun 21 '17 at 06:57

2 Answers2

8

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-Warning “warning”
Write-Error “error”
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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • Is that a Powershell build step? I don't seem to have that option. We're using TFS 2015. – John Mills Jun 15 '17 at 22:20
  • @GiddyUpHorsey This option is available with TFS2017 update2RC or VSTS. On TFS2015, I'm afraid it's not able to bypass it if any data is written to the Standard Error stream for the build-in powershell step. You may have to use *Continue on error* option. – PatrickLu-MSFT Jun 16 '17 at 02:04
  • That is unfortunate. `Continue on error` isn't helpful in this situation. TFS 2015 Powertools doesn't seem to work properly with redirecting the error stream. – John Mills Jun 21 '17 at 07:08
  • 1
    Also not possible to change under [Azure Powershell task](https://learn.microsoft.com/en-us/vsts/pipelines/tasks/deploy/azure-powershell?view=vsts) – Artyom Jun 26 '18 at 14:07
7

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Almogo
  • 81
  • 2
  • 3