淘宝商城(天猫)高级技术专家.3年研发+3年性能测试调优/系统测试+4年团队管理与测试架构、研发系统实践. 新舞台新气象, 深化测试基础架构及研发架构,希望能在某个技术领域成为真正的技术大牛。欢迎荐才http://bbs.51testing.com/viewthread.php?tid=120496&extra=&page=1 .邮件: jianzhao.liangjz@alibaba-inc.com,MSN:liangjianzhao@163.com.微博:http://t.sina.com.cn/1674816524

彻底删除hudson job的方法

上一篇 / 下一篇  2012-03-08 10:56:47 / 个人分类:java开发

官方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;   

}

 

三) Hudson.FileSystemProvisioner

 

此处需要实现序列化。并且各个slave重新下载slave.jar且重连。

 

discardWorkspace加入激活slave删除文件夹的功能。

 

publicstaticfinalclassDefaultextendsFileSystemProvisionerimplements  Serializable{

       /**

 

      publicvoidprepareWorkspace(AbstractBuild<?, ?> build, FilePath ws, TaskListener listener)throwsIOException, InterruptedException {

       }

         

       publicvoiddiscardWorkspace(AbstractProject<?, ?> project, FilePath ws)throwsIOException, InterruptedException {

       //add byliangjz,递归删除文件参考ZFSProvisioner

       ws.act(newFileCallable<Void>(){

               publicVoid invoke(File f, VirtualChannel channel)throwsIOException {

                   if(f!=null){

                     Util.deleteRecursive(f);

                   }                      

                   returnnull;

               }

           });

       }

 

 

 


TAG: hudson Hudson job

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar