我想编写一个groovy脚本,将所有项目从给定视图复制到具有新名称的新视图(请参阅下面的代码),并且还将更改配置 - 将字符串从旧值替换为新值。 我可以将作业复制到新视图,但如何修改它们? 假设我需要在作业配置中将'MR222'的每次出现更改为'MR999'。
/* Variables */
def oldViewName = 'orig Name'
def newViewName = 'new Name'
def search = 'MR222'
def replace = 'MR999'
/* If new view doesnt exist create new view */
if ( ! Hudson.instance.getView(newViewName) ) {
def newView = new ListView(newViewName)
Hudson.instance.addView(newView)
/* For each job in old view, copy it, replace workspace and add to new view */
Hudson.instance.getView(oldViewName).getItems().each { item ->
AbstractProject project = Hudson.instance.copy(item, item.getName().replace(search, replace))
if (project.getCustomWorkspace()) {
project.setCustomWorkspace(project.getCustomWorkspace().replace(search, replace))
}
newView.add(project)
}
}
else {
println "View \"${newViewName}\" already exist"
}