官方hudson2.0.1删除job时,并没有删除各次build的历史记录。本次改动hudson代码删除在master上的配置文件及各个还残留build记录的slave上的build记录。
一) hudson.model.AbstractProject.performDelete()
修改为获取所有的build记录上的Node并执行删除操作。
@Override
protectedvoidperformDelete()throwsIOException, InterruptedException {
// prevent a new build while a delete operation is in progress
makeDisabled(true);
//modify byliangjz
//FilePathws= getWorkspace();
//if(ws!=null) {
/*
Node n = getLastBuiltOn();
getScm().processWorkspaceBeforeDeletion(this,ws, on);
if(on!=null)
on.getFileSystemProvisioner().discardWorkspace(this,ws);
*/
Map<Node,FilePath> nfMap = getAllBuiltOn();
for(Map.Entry<Node,FilePath> entry:nfMap.entrySet())
{
Node n=entry.getKey();
FilePath fp=entry.getValue();
getScm().processWorkspaceBeforeDeletion(this, fp, n);
if(n!=null)
n.getFileSystemProvisioner().discardWorkspace(this,fp);
}
//}
super.performDelete();
}
二)hudson.model.Job获取所有的曾经build过的节点及workspace目录
publicMap<Node,FilePath> getAllBuiltOn() {
// where was it built on?
ListallBuild =getAllBuild();
Map<Node,FilePath> map=newHashMap<Node,FilePath>();
Set<Node> nodes=newHashSet<Node>();
for(Object o: allBuild){
AbstractBuildb=(AbstractBuild) o;
Node n= b.getBuiltOn();
if(!nodes.contains(n)){
FilePath ws=b.getWorkspace();
if(ws!=null){
map.put(n,ws);
nodes.add(n);
}
}
}
returnmap;
}