February 2012

Forcing Jenkins jobs that fail to be considered a success

So apparently my drupal-cron job in our Jenkins instance has been failing for around 5 days now, whatever. It's not doing anything it shouldn't, drush is just failing when it can't find a valid site. It really shouldn't be a failure, but Jenkins doesn't know that.

Jenkins decides on success/failure based on the exit code left by the last command ran. So if something ends with an exit 1 it will mark it as a failure, on the other hand if it ends with an exit 0 Jenkins will say that the job is a success.

So how do you fix this problem? Tell Jenkins that the script finished with a exit 0, duh. I went from this:

#!/bin/bash
DRUSH=/usr/local/bin/drush

for d in $(find $HOME/projects/dev -type d -depth 1)
do
  $DRUSH -r $d cron
done

The job's output is something like this:

Command core-cron needs a higher bootstrap level to run - you will       [error]
need invoke drush from a more functional Drupal environment to run
this command.
The drush command 'cron' could not be executed.                          [error]
The directory /Users/zach/projects/dev/mustache.appstate.edu does not    [error]
contain a valid Drupal installation
Cron run successfully.                                                 [success]
Cron run successfully.                                                 [success]
Command core-cron needs a higher bootstrap level to run - you will       [error]
need invoke drush from a more functional Drupal environment to run
this command.
The drush command 'cron' could not be executed.                          [error]
The directory /Users/zach/projects/dev/weathercams does not contain a    [error]
valid Drupal installation
Build step 'Execute shell' marked build as failure
Finished: FAILURE

If you add the exit 0 to the script and make it look like this: #!/bin/bash DRUSH=/usr/local/bin/drush

for d in $(find $HOME/projects/dev -type d -depth 1)
do
  $DRUSH -r $d cron
done
exit 0

Things look a bit better:

Command core-cron needs a higher bootstrap level to run - you will       [error]
need invoke drush from a more functional Drupal environment to run
this command.
The drush command 'cron' could not be executed.                          [error]
The directory /Users/zach/projects/dev/mustache.appstate.edu does not    [error]
contain a valid Drupal installation
Cron run successfully.                                                 [success]
Cron run successfully.                                                 [success]
Command core-cron needs a higher bootstrap level to run - you will       [error]
need invoke drush from a more functional Drupal environment to run
this command.
The drush command 'cron' could not be executed.                          [error]
The directory /Users/zach/projects/dev/weathercams does not contain a    [error]
valid Drupal installation
Finished: SUCCESS