Due to some maintenance issues, this service has been switched in read-only mode, you can find more information about the why

and how to migrate your plugin documentation in this blogpost

Skip to end of metadata
Go to start of metadata

This script enumerates all projects belonging to a specific view and clones them. This is very handy if you created a new branch and need to setup build automation for it. The script has ample opportunity for improvement, error checking, only a single save etc, but it took me a while to make this work and wanted to share the progress so far. So if you have improvements, feel free to add them :-)

This is what the script does in detail:

  • enumerate all projects that belong to a view
  • clone each project
  • give it a new name
  • disable the project
  • update the custom workspace

Note: the script assumes that you have a custom workspace declared, which all our projects have. If you don't have that, just take out the part of the code.

import hudson.model.*
def str_view = "MyProduct_Release_1.0"
def str_search = "Rel_1.0"
def str_replace = "Rel_1.1"
def view = Hudson.instance.getView(str_view)
//copy all projects of a view
for(item in view.getItems())

  //create the new project name
  newName = item.getName().replace(str_search, str_replace)

  // copy the job, disable and save it
  def job = Hudson.instance.copy(item, newName)
  job.disabled = true
  // update the workspace to avoid having two projects point to the same location
  AbstractProject project = job
  def new_workspace = project.getCustomWorkspace().replace(str_search, str_replace)
  println(" $item.name copied as $newName")

  • No labels


  1. Unknown User (alper_tekinalp)

    Hi. When I run the code it gives "null pointer exception" on line 27 where try to create a new workspace. getCustomWorkspace() returns null.

    Edit: Sorry, I missed the note part.

  2. Unknown User (sbuisson)

    Excellent !! thank you very much !!

  3. Unknown User (dhruvit01)

    Thank you very much for the script. Can i get a help on how and where this script is suppose to run??