Jenkins 使用脚本批量复制任务
import hudson.model.*
//源view
def str_view = "Test-Front"
//目标view
def str_new_view = "Test02-Front"
//源job名称(模糊匹配)
def str_search = "Test-Front"
//目标job名称(模糊匹配后替换)
def str_replace = "Test02-Front"
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
}
//是否禁用任务,false不禁用,true禁用
job.disabled = false
job.save()
Hudson.instance.getView(str_new_view).add(job)
println(" $item.name copied as $newName")
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通