Jenkins:使用Groovy清洁工作区 [英] Jenkins : Clean workspaces with Groovy

查看:143
本文介绍了Jenkins:使用Groovy清洁工作区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Jenkins安装程序没有节点,所有构建都在同一台机器上运行. 我想设置一个Groovy脚本来清理旧的工作区,所以我想使用:

I have Jenkins setup without nodes, all builds are run on the same machine. I want to setup a Groovy script to cleanup old workspaces, so I want to use:

proj.scm.processWorkspaceBeforeDeletion(@Nonnull Job<?,?> project,
                                        @Nonnull FilePath workspace,
                                        @Nonnull Node node)

在主服务器上,我应该为node设置什么值?

What value should I put for node when on master?

推荐答案

执行以下脚本以使用Groovy清理所有Jenkins工作区:

Execute below script to clean-up all Jenkins workspaces with Groovy:

import hudson.model.* // For each project

for(item in Jenkins.instance.items)      
{ // check that job is not building
    if(!item.isBuilding())     
    { 
         println("Wiping out workspace of job "+item.name)    
         item.doDoWipeOutWorkspace() 
    } else { 
         println("Skipping job "+item.name+", currently building") 
    } 
 }

这篇关于Jenkins:使用Groovy清洁工作区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆