Hudson script console

Along with Configure System we have some more options in Manage hudson. We have script console to execute arbitrary script for administration, Maven 3 Configuration, System Information to know details about system like environment variable, Reload Configuration from Desk to clear the memory and reload the jobs from file system and System Log for Hudson etc.

Configure System in Manage hudson

Scripts in Hudson

To Scripts in Hudson, click on the Manage Hudson link in the left-hand navigation menu, and then click on Script Console. Type in an arbitrary Groovy script and execute it on the server. It is useful for trouble-shooting and diagnostics.

Sample Scripts:

Disable all jobs-- this script is for to disable/enable all jobs in you hudson server.

import hudson.model.*
// For each project
for(item in Hudson.instance.items) {
      println("JOB : "+item.name)
      item.disabled=false     //Enabled,  item.disabled=false  Disabled
      item.save()
      println("\n=======\n"+ item.disabled)
}

Scripts in hudson

Failed Jobs--This scripts displays a list of all failed jobs. Addon: restart them.

// Get the list of failed jobs
activeJobs = hudson.model.Hudson.instance.items.findAll{job -> job.isBuildable()}
failedRuns = activeJobs.findAll{job -> job.lastBuild != null 
		&& job.lastBuild.result == hudson.model.Result.FAILURE}
// Do something with them - e.g. listing them
failedRuns.each{run -> println(run.name)}

Priniting Failures jobs in hudson using scripts