需要将jenkins中某一个view中的所有job都复制到另外一个view中,一个一个复制有点蛋疼,所以查询了一下资料,使用groovy scripts 来实现这个功能
- 新建view
- 打开系统管理 -> 脚本命令行
import hudson.model.* //源view def str_view = "AOSIT_Frontend_SONAR" //目标view def str_new_view = "PTTEST_Frontend_SONAR" //源job名称(模糊匹配) def str_search = "-aosit-sonar" //目标job名称(模糊匹配后替换) def str_replace = "-pttest-sonar" 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") }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。