Last active
June 8, 2020 02:08
-
-
Save euccas/21f2f1b62ab0c883236e281b6a0e2227 to your computer and use it in GitHub Desktop.
Copy all jobs in a view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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