在jenkins平台运行一个脚本来实现
    image.png
    image.png
    脚本内容如下:
    目标视图需要先创建好

    1. import hudson.model.*
    2. //源view
    3. def str_view = "test-sextant-dev"
    4. //目标view
    5. def str_new_view = "test"
    6. //源job名称(模糊匹配)
    7. def str_search = "sextant-"
    8. //目标job名称(模糊匹配后替换)
    9. def str_replace = "zzzzzzzzzz-"
    10. def view = Hudson.instance.getView(str_view)
    11. //copy all projects of a view
    12. for(item in view.getItems())
    13. {
    14. //跳过未模糊匹配到的构建 任务
    15. if (!item.getName().contains(str_search)) {
    16. // 说明文字,表示跳过未匹配到的job,可加可不加
    17. // println("but $item.name ignore ")
    18. continue
    19. }
    20. //create the new project name
    21. newName = item.getName().replace(str_search, str_replace)
    22. // copy the job, disable and save it
    23. def job
    24. try {
    25. //因为第一次导入后报错,所以添加了try-catch 跳过已存在的job
    26. job = Hudson.instance.copy(item, newName)
    27. } catch(IllegalArgumentException e) {
    28. // println(e.toString())
    29. println("$newName job is exists")
    30. continue
    31. } catch(Exception e) {
    32. println(e.toString())
    33. continue
    34. }
    35. job.disabled = true
    36. job.save()
    37. // update the workspace to avoid having two projects point to the same location
    38. //下面开启后会报错,原因是groovy不用重新创建对象,注释后正常
    39. //AbstractProject project = job
    40. //def new_workspace = project.getCustomWorkspace().replace(str_search, str_replace)
    41. //project.setCustomWorkspace(new_workspace)
    42. //project.save()
    43. //add job to view
    44. Hudson.instance.getView(str_new_view).add(job)
    45. println(" $item.name copied as $newName is success")
    46. }