Skip to content

Instantly share code, notes, and snippets.

@euccas
Last active June 8, 2020 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save euccas/21f2f1b62ab0c883236e281b6a0e2227 to your computer and use it in GitHub Desktop.
Save euccas/21f2f1b62ab0c883236e281b6a0e2227 to your computer and use it in GitHub Desktop.
Copy all jobs in a view
import hudson.model.*
def str_view = "AIR_Project_A630"
def str_search = "air_a630"
def str_replace = "air_a630v1"
def view = Hudson.instance.getView(str_view)
//copy all projects of a view
for(item in view.getItems())
{
//create the new project name
def oldname = item.getName()
if (oldname) {
def 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
job.save()
// update the workspace to avoid having two projects point to the same location
AbstractProject project = job
def old_workspace = project.getCustomWorkspace()
if (old_workspace) {
def new_workspace = project.getCustomWorkspace().replace(str_search, str_replace)
project.setCustomWorkspace(new_workspace)
project.save()
}
println(" $item.name copied as $newName")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment