jenkins批量复制view中所有job
1、新建view
2、打开系统管理
3、打开脚本命令行
4、//源view def str_view = "dev-XX" //目标view def str_new_view = "dev-FF" //源job名称(模糊匹配) def str_search = "dev-XX" //目标job名称(模糊匹配后替换) def str_replace = "dev-FF" 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 try { //因为第一次导入后报错,所以添加了try-catch 跳过已存在的job job = Hudson.instance.copy(item, newName) } catch(IllegalArgumentException e) { println(e.toString()) println("$newName job is exists") continue } catch(Exception e) { println(e.toString()) continue } job.disabled = true job.save() // 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) project.setCustomWorkspace(new_workspace) project.save() //add job to view Hudson.instance.getView(str_new_view).add(job) println(" $item.name copied as $newName") }
5、刷新新建的视图,看看项目被复制过来没有。如果没有,则编辑视图
6、复制的项目会出现在列表中,勾选归类到该视图下
7、目的已经实现,偷懒成功,耶耶😚