Jenkins: Is there any way to cleanup Jenkins workspace?

后端 未结 11 1825
既然无缘
既然无缘 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条回答
  • 2020-11-29 03:51

    You will need to install this plugin before the options mentioned above will appear

    Workspace Cleanup Plugin

    This plugin add the check box to all job configs to allow you to delete the whole workspace before any steps (inc source control) are run

    This is useful to make sure you always start from a known point to guarantee how you build will run

    0 讨论(0)
  • 2020-11-29 03:52

    There is a way to cleanup workspace in Jenkins. You can clean up the workspace before build or after build.

    First, install Workspace Cleanup Plugin.

    To clean up the workspace before build: Under Build Environment, check the box that says Delete workspace before build starts.

    To clean up the workspace after the build: Under the heading Post-build Actions select Delete workspace when build is done from the Add Post-build Actions drop down menu.

    0 讨论(0)
  • 2020-11-29 03:54

    Workspace Cleanup Plugin

    In Jenkins file add

    cleanWs()
    

    This will delete the workspace after the build is complete

    0 讨论(0)
  • 2020-11-29 03:58

    If you want to manually clean it up, for me with my version of jenkins (didn't appear to need an extra plugin installed, but who knows), there is a "workspace" link on the left column, click on your project, then on "workspace", then a "Wipe out current workspace" link appears beneath it on the left hand side column.

    0 讨论(0)
  • 2020-11-29 03:58

    If you want to just remove one dir (or file) you can use Groovy and Manage Jenkins → Scripts Console run a script which removes it.

    For example, you can look at the files with:

    dh = new File('./bitnami/jenkins/jenkins_home/workspace/jobname/folder')
    dh.eachFile {
      println(it)
    }
    

    And then, when you have the folder you want to delete in dh, you could simply append the next code:

    dh.deleteDir()
    

    And it will be deleted.

    Note: The path shown in the example is for a Bitnami Jenkins installation, yours could be different.

    0 讨论(0)
提交回复
热议问题