Skip to content

Instantly share code, notes, and snippets.

@obcode
Last active February 21, 2023 16:09
Show Gist options
  • Select an option

  • Save obcode/ee44e6d4fbeadd99e2bb to your computer and use it in GitHub Desktop.

Select an option

Save obcode/ee44e6d4fbeadd99e2bb to your computer and use it in GitHub Desktop.
Jenkins - Copy all Jobs from a view into another view
import hudson.model.*
def oldview = "Braun-SwArch"
newview = new ListView("Braun-SwArch-Milestone1")
def view = Hudson.instance.getView(oldview)
//copy all projects of a view
for(item in view.getItems())
{
//create the new project name
newName = item.getName() + "-Milestone1"
// copy the job, disable and save it
def job = Hudson.instance.copy(item, newName)
newview.add(job)
println(" $item.name copied as $newName")
}
Copy link

ghost commented Dec 4, 2017

I get an exception while running this. A NullPointerException

@jalex19100
Copy link

Worked fine for me - modified view names, obviously.

@AATHITH
Copy link

AATHITH commented Feb 19, 2023

I get an exception while running this. A NullPointerException

I'm getting the same.

A step-by-step instruction on how to perform this task will be helpful.

@jalex19100
Copy link

You can also run this script in the Jenkins script console. Modify the old-view, new-view and job names and paste into the console . However, this was for older versions of Jenkins. I am not sure how accurate this is today. You should not be running this without knowing what it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment