How to return "Not built" to Gerrit Trigger Plugin - jenkins

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 .

Related

Jenkins build stuck after "exit 0" status, and its taking long time to exit from that

I have a few Jenkins build jobs for compiling a .NET application using npm, msbuild, and unit test case execution steps.
It shows build success and hangs after exit 0 status, because of that downstream jobs are delayed and failing after long waiting time.
Is it some process blocking or some plugin issue?
PS: I don't want to use build-timeout plugin as the build is already showing success but taking too long to exist from that job.
I had the same issue and added"-DSoftKillWaitSeconds=0" in jenkins.xml before the -jar option. Now jobs execute normally for me. Link to solution

How to stop a jenkins job midway?

I clicked on execute shell 3 times and have 3 shell scripts that jenkins runs during a build. How do I end a job mid build in one of the scripts?
I tried exit but that only ends the particular script and not the job.
If you click on the (?) help icon next to the "Execute Shell" field in your job configuration, you'll see that it says:
the build is considered a failure if any of the commands exits with a non-zero exit code.
Therefore, if you detect that you want to stop the build from a shell script, you can use exit 1 (to signify failure) rather than just calling exit, which is equivalent to exit 0 (which signifies success).
This will stop the build immediately, marking it as a failure — no other build steps will be 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

Cucumber test passed, but jenkins failed

I have a lots of tests on several server. I use Jenkins to manage all of them.
On one server (Slave Windows), when I launch a test in cmd, I got something like :
c:/tests/cucumber --tag #dev -p ie
...
1 scenarios (1 passed)
12 steps (12 passed)
0m31.761s
echo %errorlevel%
0
No error in the tests, and cucumber seems good.
When jenkins launch exactly the same tests, I get :
c:/jenkins_folder/cucumber --tag #dev -p ie
...
1 scenarios (1 passed)
12 steps (12 passed)
0m28.453s
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
The test passed, but is marked failed by jenkins.
The command "echo %errorlevel%" is aborted : the job fail before this point.
The same job played on another slave work.
Same problem with all profile and all tags.
Same problem when I replace profile by real value
I don't use the --strict flag
Jenkins, plugins : all up-to-date
Code of the windows batch :
cd /test8folder
cucumber --tag #dev -p ie
echo %errorlevel%
What did I missed ?
There doesn't seem to be anything wrong with the configuration.
The fact that you get Build step 'Execute Windows batch command' marked build as failure after your cucumber command without actually seeing the echo %errorlevel% executed only reaffirms that there was an error in cucumber (more on that later).
However, in Execute Windows Batch Command, even a command in error would not exit the batch script (unlike Jenkins's default Execute Shell implementation). You should be seeing at least some exit code, 0, 1, or anything.
The only time this would happen is if something within your buildstep executed exit /b [exit_code_num]. I don't know "cucumber", but if that is in-fact a cucubmer.bat and inside there is an exit /b statement, this is what's causing it drop out of the buildstep without continuing.
Solution
You can use call cucumber [whateverparams] so that even when it quits with exit /b, the control will return to the calling process, the Execute Windows Batch command script.
Try that first. And you will probably see that your echo %errorlevel% will probably return a non-zero value when executed under Jenkins, but at least you will see it now.
Now, as for why it succeeds on command prompt, but fails within Jenkins, there could be a lot of reasons, the most common one being environment variables and paths. We can tackle that later once we actually see the exit code of cucumber. You also said it worked on another node: even more reason to believe this is an environment issue, maybe a non-existent folder...
Edit:
The reason that even "successful" test execution exits the calling script is because exit /b 0 would still quit the calling script, even though cucumber exited with "success" 0

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

Resources