I have a VSTS (Azure DevOps) build which contains a PowerShell or a Command line task. This task is running some program: program.exe
. When program.exe
returns a non-zero exit code, the build is failed as expected. program.exe
also prints a detailed error message to the stderr
stream in case of an error.
The problem is that the content of the stderr
stream is not passed to the build. The task is always returning the following error message which is also displayed as a build failure message on the build summary tab:
Process completed with exit code 1.
Which is useless. The user has to look for a failed task, open its output and search for an error message there. That's not very convenient.
How to easily pass the content of stderr
to the build?
Do I have to manually capture stderr
and then send it to the build using PowerShell or is there a setting to change the build behaviour to work as I expect?
$(Build. SourcesDirectory) : The local path on the agent where your source code files are downloaded.
I just added "2>&1 | Write-Host
" to the command so that the stderr stream will be routed to the Write-Host stream. Reference this thread: VSTS build fails with "Process completed with exit code 0 and had 3 error(s) written to the error stream." even though I set my PowerShell script to ignore errors
You can also try uncheck the Fail on Standard Error
in your PowerShell script configuration and write the lastexitcode to pass the task:
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 waring"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With