官方hudson2.0.1刪除job時(shí),并沒(méi)有刪除各次build的歷史記錄。本次改動(dòng)hudson代碼刪除在master上的配置文件及各個(gè)還殘留build記錄的slave上的build記錄。
一) hudson.model.AbstractProject.performDelete()
修改為獲取所有的build記錄上的Node并執(zhí)行刪除操作。
@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,F(xiàn)ilePath> nfMap = getAllBuiltOn();
for(Map.Entry<Node,F(xiàn)ilePath> 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獲取所有的曾經(jīng)build過(guò)的節(jié)點(diǎn)及workspace目錄
publicMap<Node,F(xiàn)ilePath> getAllBuiltOn() {
// where was it built on?
ListallBuild =getAllBuild();
Map<Node,F(xiàn)ilePath> map=newHashMap<Node,F(xiàn)ilePath>();
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;
}