Last active
February 21, 2023 16:09
-
-
Save obcode/ee44e6d4fbeadd99e2bb to your computer and use it in GitHub Desktop.
Jenkins - Copy all Jobs from a view into another view
This file contains hidden or 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 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") | |
| } |
Worked fine for me - modified view names, obviously.
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.
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
I get an exception while running this. A
NullPointerException