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?
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
Related
how to fail the GO build based on the sonar quality gate?
I expect the stage to be failed when gateway fails. Is there any configurations that can be done to fail the build
Based on #moritz answer, this worked for me.
I created a bat file that would check for the status code of the SONAR project, after the SONAR build is executed and based on the status of the response, would return the exit code.
For /F "Delims=" %%A In ('"curl http://mysonarserver/api/qualitygates/project_status?projectKey=com.mypackage:sampleproject | jq ".projectStatus.status""') Do Set "test=%%~A"
echo %test%
If /I "%test%"=="ERROR" exit -1
If /I "%test%"=="OK" exit 0
In my case, the SONAR server would return ERROR and OK based on the status of the build.
I have used curl and jq for making the http request from the command line and to parse the response to json respectively.
I had to do some tweaking to make it work on Windows, hopefully it should work on Linux as well.
You can also add the call to the Maven build for Sonar from this script if needed.
I hope it helps!
GoCD fails the task (and thus stage and job, unless configured otherwise) when the exit code is non-zero.
So you need to bring whatever command you are executing to indicate a failure through a non-zero exit code (which most UNIX commands do).
According to Microsoft, "If [the system] cannot locate the DLL, the system terminates the process and displays a dialog box that reports the error. " This is the result I get when I run my application outside of the command line, but I do not get the same system error when I run the application from a shell environment such as command prompt or powershell.
Is there a way to show the same error message when the application is run from a command line interface?
https://msdn.microsoft.com/en-us/library/aa271571(v=vs.60).aspx
SetErrorMode(GetErrorMode() & ~SEM_FAILCRITICALERRORS);
but I don't think you want to do this, as you do not know in which environment the user will run your application.
It is usually now a good idea to popup a dialogbox in e.g. a service environment.
What is the problem with examining the error code of whatever is failing e.g. LoadLibrary() and reacting to this error?
We are using IBM Rational Test RealTime for unit testing of ANSI-C code. It's my job to tell a Jenkins server to run those tests automatically.
Documentation suggests what command line should be used:
studio -r <node>.{[.<node>]} <project_file> [-html <directory>]
Unfortunately running studio -r with any more parameter does not output anything to the console. If it does not do the intended unit testing job, it terminates immediately and gives no error message whatsoever. This is frustrating. The error class can be deduced from the exit code, but that is not really enough for troubleshooting.
Any idea where to find error output? I can not find any log file.
The detailed command line syntax is described here,
but this claims, what apparently is not true:
All messages are sent to the standard error output device.
If it runs successfully missing console output can be tollerated, but if it fails to run the test, I really, really would like to see the stuff that is normally output into the RTRT main window. Note: a unit test that fails
e.g. on an assertion is counted as "successful" test run in this context.
I am implementing a Powershell build script for teamcity to test some functionality, but cannot figure out out to report an error.
I am trying to follow this description:
https://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingTests
However, although the script actually results in some tests being registered, it refuses to report errors. I am now back to the basic example from the . I have the following Powershell build step (error output: error, script: source):
Write-Host("##teamcity[testStarted name='className.testName']")
Write-Host("##teamcity[testStdErr name='className.testName' out='error text']")
Write-Host("##teamcity[testFinished name='className.testName']")
Resulting build log (verbose):
[13:27:12]Step 1/5: Output to build log (Powershell)
[13:27:13][Step 1/5] ##teamcity[buildStatisticValue key='buildStageDuration:firstStepPreparation' value='156.0']
[13:27:13][Step 1/5] ##teamcity[buildStatisticValue key='buildStageDuration:buildStepRUNNER_18' value='0.0']
[13:27:13][Step 1/5] Starting: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -Command - < D:\JetBrains\buildagent\temp\buildTmp\powershell6640337654487221076.ps1
[13:27:13][Step 1/5] in directory: D:\JetBrains\buildagent\work\7e3fac8e390ca38d
[13:27:13][Step 1/5] className.testName
[13:27:13][className.testName] [Test Error Output] error text
[13:27:13][Step 1/5] Process exited with code 0
[13:27:13][Step 1/5] ##teamcity[buildStatisticValue key='buildStageDuration:buildStepRUNNER_18' value='536.0']
I.e. the test is registered in teamcity as executed bit it succeeds! I would expect the test to fail, due to the 'testStdErr' output! What it the correct way to make it fail?
Thanks,
Kim
You should use the testFailed directive which is listed on the page you linked:
##teamcity[testFailed name='MyTest.test1' message='failure message' details='message and stack trace']
Or change the build failure condition settings under 'Build Failure Conditions' to fail the build if you write to stderr (edit: this is my understand of the docs anyway):
Fail build if:
[ ] an error message is logged by build runner
I would like to process some operations only if the build failed. For example, if runtime execution has thrown a core dump (it doesn't happen always, of course) and I want to move it somewhere, so that the next day build won't remove it.
Does anyone know how to perform anything in case a build fails?
Try Groovy Postbuild Plugin. With this you can use hudson api's to check if the build is a failure or not, and then do the required actions using groovy script. For example, you can use following script to check if the build is unstable or better
if(manager.build.result.isBetterOrEqualTo(hudson.model.Result.UNSTABLE))
{
\\ do something
}
Well if it is set up to log to std out, it will be in the Jenkins log, if not, can you set it up to log to a file in you workspace , then you can package as an artifact based on the name... If you are running in a posix system you can redirect stderr to stdout and direct those both to a file in your run command. Or pipe them through tee, so you get them in both