TFS 2015 vNext Build - Set build result - tfs

How can we set the build result/outcome from lets say a powershell script.
I believe the valid states are Successful, Failed and Partially Successful, but especially for the last, how can we set that one manually. if we return error 1, the script task will have a failed state and the build as well.
We have some scenarios where we want to set the build to Partially Successful.
Im not able to find any documentation about this.

There are a few things to understand:
A task with a non-zero exit code fails.
A build fails if a task fails.
...unless the "Continue on Error" checkbox is selected, in which case it marks the build as "Partially succeeded" and continues running other tasks.

Related

Ignore failure of post build step in Jenkins

I have Jenkins job with summary plugin step in post build actions. Sometimes it fails because of absence of the necessary file for it(for some branches, and there is no ability to update them nearest time). Is it possible to ignore failure only in post build steps and mark build green?
Finally I found solution - in build steps add shell step with command "touch summaryName.xml". If file exists it won't be changed. And if there is no summary file it will be created
Yes, you can ignore the failure by ticking the check box [Do not fail this build if archiving returns nothing] in advanced section.

How to return "Not built" to Gerrit Trigger Plugin

There are 4 kind gerrit command in gerrit plugin settings.
Success / Fail / Unstable / Not Built.
I could return "success/fail" from my job to gerrit plugin, by using exit 0/1,
And "success/fail" gerrit command was executed.
But I don't Understand how to return "Not Built" by shellscript.
Please teach me.
sorry for my poor english.
Thanks.
Success / Failure / Unstable
If the job has no test reports configured:
If the last build command executed by Jenkins exits with failure
(<> 0) exit code, the build is considered to be failed.
If the last build command exits with success (= 0) exit
code, the build is successful.
If the job has one or more test reports configured:
If the last build command executed by Jenkins exits with failure
(<> 0) exit code, the build is considered to be failed.
If the last build command exits with success (= 0) exit
code but test reports have some failed tests, the build is unstable.
If the last build command exits with success and all test have
passed, the build is stable.
The only other way to get "Unstable" result is through the use of some post-build plugins (like static code analysis for example).
Not Built
I'm not sure about this item... but I think (guess) the build is considered not build when the job finishes by a timeout.
I found out way of force stopping by following command
curl http://127.0.0.1:8080/job/${JOB_NAME}/${BUILD_NUMBER}/stop
and gerrit command for "Not Build" was executed .

Jenkins - Build Status

I've created one Jenkins job to execution 5 test cases and it works, but not in terms of build creation.
Build status is coming as SUCCESS even if there is any failure test
cases during execution.
For instance, 2 test cases out of 5 got failed during my recent run, but the build status has become SUCCESS!!!
Please help me in correcting this.....
Note: I'm using Jenkins 1.617 & ANT 1.9.4 for the integration.
If you are executing junits in jenkins, default status is unstable for jenkins job and success for maven/ant build.
If you are using an ant build add the below property to junit task to make the build failed failureproperty="test.failed". If you want to fail the build even if one junit fails, add property haltonfailure="yes"
If you are using maven add the argument -Dmaven.test.failure.ignore=false

YSlow Phantomjs and Jenkins jobs failing, but analysis successful

I'm going through the tutorial on YSlow and Phantom js in Jenkins here: http://yslow.org/phantomjs/
Everything appears to be working great except the Jenkins builds are failing. I think this is due to the violations that YSlow is finding (6 for the particular site I am measuring). I'd rather have the build be successful (or unstable) vs. failed though
Is that possible with this or will I have to resort to something like the postgroovy or text finder plugin?
This is the console output:
phantomjs.exe yslow.js -i grade -t 50 --format junit http://www.somesite.com 1>yslow.xml
D:\Apps\Jenkins\workspace\YSlow_Test>exit 6
Build step 'Execute Windows batch command' marked build as failure
Thanks
Any non-zero exit code at the end of your Execute Windows batch command build step will result in build step being marked as failure.
To have the build step marked as success, you need an exit code of 0. I don't know anything about "yslow" or "phantomjs" and why they are giving you exit code of non-zero, but from "batch" side of things, you need only write exit 0 at the end of your build step if you want to overwrite the exit code of your phantomjs command.
You can then use Text Finder plugin to parse the console log and mark build as unstable when certain conditions are met.
Reading over this answer, Configuring yslow on Jenkins looks like you need TAP plugin to have the functionality of unit testing marking the build as unstable automatically

How to run a conditional step in Jenkins only when a previous step fails

I'm trying to create a 2 step job in Jenkins. I want the second step only to run if the first step fails. (The first step executes a unit test to see if the code I'm compiling is good - if it is not then i want to run some diagnostics in the second step).
The conditional step plug seems a good choice for this. However, I can't work out how to use the conditional step plug in to cause the second step to run when the first step fails.
The conditional step plug in offers a list of conditions such as 'Never', 'Boolean condition' ... and 'Current Build Status'. I would have thought I should use a 'Current Build Status' condition and set the worst status to 'failed' and the best status to 'unstable'. Then if the first step fails, the second step will run.
However there seems to be a problem with this. When the first step fails, then Jenkin's stops the job at the point. So the second step never has a chance to evaluate its condition and see whether or not it should run.
So I can't see how the use of a 'Current build status' of failed could ever be used in the conditional step plugin - as if the build has already failed, we never get to the Conditional Step. How can one mark the build status as failed in step 1 but not have Jenkins then stop the job at that point?
many thanks
Dave Sinclair
An inelegant way out will be to use the "Post Build task plugin".
It can parse the build log. So you can set it to check for failure logs statements. Once found you can launch a script. Maybe you can trigger second build via this script.
I am sure that there will be some other elegant options out there in post build tasks ecosystem. I am watching this question to see Jenkins experts to answer it.
You can create a script build step that always succeeds. In that script you could create one file when everything is right, another when something went wrong. You can check for the existence of the files in two separate conditional build steps. For instance:
REM Clean up flags
del build_failed
del build_ok
REM This should be the actual buildstep
REM Foobar does not exist, so it will return an error. dir will always work. Exchange the REM between the two lines to test both scenarios
dir foobar
REM dir
REM Set the flags based on the build step status
IF NOT %ERRORLEVEL% == 0 (
echo > build_failed
) ELSE (
echo > build_ok
)
REM Ensure that this step will always pass
EXIT 0
https://plugins.jenkins.io/postbuildscript/ should do the job. It allows to run a script if the build failed or even got aborted.

Resources