Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hudson/jenkins: disable the failed build

Tags:

jenkins

hudson

What is the preferred way to disable the periodical build when it has failed? Quick search showed that there is a Prerequisite build step plugin, but that fails the build, and I need the build to be completely disabled until manual intervention.

Thanks.

like image 824
Vladimir Sinenko Avatar asked Dec 02 '22 02:12

Vladimir Sinenko


2 Answers

Okay, I think I managed to find a solution.

  • Retry Failed Builds plugin didn't work because it could not override the default project schedule, so the failed project got built again and again.
  • Naginator plugin didn't work because the delay is not configurable.
  • Prerequisite build step plugin is not suitable.

The solution is to install the Groovy Postbuild Plugin, which is run under the Jenkins JVM and exposes the Jenkins instance publically. So it is possible to programmatically disable the current build directly in the Project configuration:

if (manager.build.result.isWorseThan(hudson.model.Result.SUCCESS)) {
  manager.build.project.disabled = true
}
like image 117
Vladimir Sinenko Avatar answered Dec 27 '22 09:12

Vladimir Sinenko


There is a button "Disable project" on the project status page. I simulate button click by HTTP POST message with data "Submit=\"Disable Project\"" like this

wget  --post-data  "Submit=\"Disable Project\"" ${JOB_URL}disable

right from the bash script which runs the build (project). The whole code can look like this

set +e
#  Run test/build
#  ....
if [ $? -ne 0 ];
then
  wget  --post-data  "Submit=\"Disable Project\"" ${JOB_URL}disable
#  Or you can use following to disable one job from another
#  wget  --post-data  "Submit=\"Disable Project\"" http://<Server>/job/$JOB_NAME/disable
  exit -1
fi

This is a rather old question, so I guess there was no Disable/Enable button in Jenkins GUI than. If Jenkins is protected by a password you will need to make wget to login first, store cookies in some file and in the second file add the cookie.

like image 41
Larytet Avatar answered Dec 27 '22 08:12

Larytet