Jenkins: Is there any way to cleanup Jenkins workspace?

后端 未结 11 1873
既然无缘
既然无缘 2020-11-29 03:18

How can I cleanup the workspace in Jenkins? I am using AccuRev as version control tool.

I created freestyle projects in Jenkins.

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 03:49

    not allowed to comment, therefore:

    The answer from Upen works just fine, but not if you have Jenkins Pipeline Jobs mixed with Freestyle Jobs. There is no such Method as DoWipeWorkspace on Pipeline Jobs. So I modified the Script in order to skip those:

    import hudson.model.*
    import org.jenkinsci.plugins.workflow.job.WorkflowJob
    
    // For each project
    for(item in Hudson.instance.items) {
      // check that job is not building
      if(!item.isBuilding() && !(item instanceof WorkflowJob))
      {
        println("Wiping out workspace of job "+item.name)
        item.doDoWipeOutWorkspace()
      }
      else {
        println("Skipping job "+item.name+", currently building")
      }
    }
    

    you could also filter by Job Names if required: item.getDisplayName().toLowerCase().contains("release")

提交回复
热议问题