1

Currently one of our Jenkins builds fails. I would like it to pass (or show green) when the build fails. At the same rate i would like our build to fail (or show red) when a case passes. The build I am configuring is our “Known Issues Build”. So only failed cases go in there. The goal of this build is for it to pass when it fails, since we know it’s broken. When our devs fix it the build should fail (which means something is working now) so that we may move it out of the build into our core build. I read an article on the --wip switch and have successfully configured that into our build. I have been receiving emails that say Jenkins build is back to normal, which to me seems like it worked. However, when you look in the build itself it looks as if it fails. The build is flagged as red, which means it failed, and the tests say they failed. The only indicator they passed is the email I receive. But this is not the intended behaviour i am going for. The build seems to alert me that it passes but looks as if it fails. Is there a way i can make the red button go green, so when we look at our builds, we know when something is wrong.

Right now I added || exit 1 to the end of my command which is supposed to reverse the failed and passed flags. I also created a short bash script to reverse the button color, which also did not work. I believe i am missing something. Any ideas? Listed below is the command I am running to launch our build:

cucumber --wip --profile wip --format json -o cucumber.json /var/lib/jenkins/workspace/Cucumber\ -\ Known\ Issues\ Build/ SITE=devel || exit 1
Nazar
  • 1,499
  • 12
  • 24
tSebastian
  • 79
  • 2
  • 8

1 Answers1

2

command || exit 1 means "If command failed, then exit 1 (i.e with failure)

You just said that you want build to fail if your command was successful, so you need:
command && exit 1 || exit 0

Above, if command is successful, then build is marked as failed, else (if command was not successful), mark the build as success

Here is the console output for the job:

Started by upstream project "Cucumber - Devel Parent Build" build number 58
originally caused by: 
Started by timer
Xvfb starting$ /usr/bin/Xvfb :75 -screen 0 1024x768x24 -fbdir /var/lib/jenkins/2013-01-25_22-24-203386303931627225842xvfb
Building remotely on dev548 in workspace /var/lib/jenkins/workspace/Cucumber - Known Issues Build
Checkout:Cucumber - Known Issues Build / /var/lib/jenkins/workspace/Cucumber - Known Issues Build - hudson.remoting.Channel@322535f5:dev548
Using strategy: Default
Last Built Revision: Revision f48428cc3128a0d6369ea99bbdbdf419bc29b173 (Cucumber/master)
Fetching changes from 1 remote Git repository
Fetching upstream changes from git@testdrivesite.beanstalkapp.com:/cucumber.git
Commencing build of Revision dad2f8792ec364e79dd76840f787d5e72676b03f (Cucumber/master)
Checking out Revision dad2f8792ec364e79dd76840f787d5e72676b03f (Cucumber/master)
Deleting old artifacts from #137
[Cucumber - Known Issues Build] $ /bin/bash /tmp/hudson3196742906607332265.sh
Using the wip profile...
Xvfb stopping
Archiving artifacts
[CucumberReportPublisher] Compiling Cucumber Html Reports ...
[CucumberReportPublisher] detected this build is running on a slave 
[CucumberReportPublisher] copying json from: file:/var/lib/jenkins/workspace/Cucumber%20-%20Known%20Issues%20Build/to reports directory: file:/var/lib/jenkins/jobs/Cucumber%20-%20Known%20Issues%20Build/builds/2013-01-25_22-24-20/cucumber-html-reports/
[CucumberReportPublisher] Generating HTML reports
Build step 'Publish cucumber results as a report' marked build as failure
Notifying upstream projects of job completion
Finished: FAILURE

This is the build steps in my configuration:

#!/bin/bash
source /usr/local/rvm/environments/default
/usr/local/rvm/gems/ruby-1.9.2-p320/bin/cucumber --profile wip --format json -o cucumber.json /var/lib/jenkins/workspace/Cucumber\ -\ Known\ Issues\ Build/ SITE=devel && exit 1 || exit 0
Deanna
  • 23,876
  • 7
  • 71
  • 156
Slav
  • 27,057
  • 11
  • 80
  • 104
  • After running the build twice, this still did not work. This is what i have: "COMMAND && exit 1 || exit 0" Does spacing matter here? i put command_&&_exit_1_||_exit_0 (of course the underscore represents a space) – tSebastian Jan 25 '13 at 13:44
  • Spacing does not matter. Maybe you could paste the console output from your job. Are there any other build steps in your job configuration? – Slav Jan 28 '13 at 14:16
  • I added some more detail to the original question for what tyou asked for. – tSebastian Jan 28 '13 at 14:33
  • You pasted the results into my answer ;) Anyways, from the console log, it is clear that it is not your `bin/cucumber` shell step that is failing the whole job. It is `Build step 'Publish cucumber results as a report' marked build as failure`. First, try removing this post-build step, and see if it behaves like you want. Second, looking at the configuration page for this plugin, under "Advanced..." section, there are 2 options that mark the build as failed. Try unchecking them. – Slav Jan 28 '13 at 15:59
  • oops...sorry bout that. and sir, you are a genius. thanks for all your help it worked like a dream!!! – tSebastian Jan 29 '13 at 15:34
  • 1
    @streetlight look at **[this answer](http://stackoverflow.com/questions/8148122/how-to-mark-a-build-unstable-in-jenkins-when-running-shell-scripts)**, it explains how to do it with "Text-finder" plugin, as well as a "Groovy Post-build" method – Slav Dec 09 '15 at 16:11