新建很多测试构建任务后,再重复建生产构建任务嫌麻烦,网上找了个脚本测试成功,在系统脚本的
import hudson.model.*
//源view
def str_view = "01--test"
//目标view
def str_new_view = "02--prod"
//源job名称(模糊匹配)
def str_search = "xxx-test"
//目标job名称(模糊匹配后替换)
def str_replace = "xxx-prod"
def view = Hudson.instance.getView(str_view)
//copy all projects of a view
for(item in view.getItems())
{
//跳过未模糊匹配到的构建 任务
if (!item.getName(). contains(str_search)) {
println(" $item.name ignore ")
continue
}
//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)