Jenkins Pipeline Wipe Out Workspace

We are running Jenkins 2.x and love the new Pipeline plugin. However, with so many branches in a repository, disk space fills up quickly.

Is there any plugin that’s compatible with Pipeline that I can wipe out the workspace on a successful build?

  • How to include git changelog in Jenkins emails?
  • Jenkins: Failed to connect to repository
  • Jenkins out of nowhere starts failing with sudo: no tty present and no askpass program specified
  • Ignoring library project with Android lint on the command line
  • How to export/import the Jenkins configuration?
  • How to run Selenium tests using TestNG framework and Jenkins
  • Maven installation settings not showing in Jenkins
  • How do I jenkins permission on a per job basis?
  • How do I dynamically trigger downstream builds in jenkins?
  • merge before build in jenkins fails but should not
  • Jenkins How can i upload a text file and use it as a parameter
  • Dynamically deploying Jenkins slaves on google compute engine for github commits
  • 4 Solutions collect form web for “Jenkins Pipeline Wipe Out Workspace”

    You can use deleteDir() as the last step of the pipeline Jenkinsfile (assuming you didn’t change the working directory).

    With, Jenkins Version 2.16 and the Workspace Cleanup Plugin, that I have, I use

    step([$class: 'WsCleanup'])
    

    to delete the workspace.

    You can view it by going to

    JENKINS_URL/job/<any Pipeline project>/pipeline-syntax
    

    Then selecting “step: General Build Step” from Sample step and then selecting “Delete workspace when build is done” from Build step

    In fact the deleteDir function recursively deletes the current directory and its contents. Symbolic links and junctions will not be followed but will be removed.

    To delete a specific directory of a workspace wrap the deleteDir step in a dir step.

    dir('directoryToDelete') {
        deleteDir()
    }
    

    We make sure we are working with a clean workspace by using a feature of the git plugin. You can add additional behaviors like ‘Clean before checkout’. We use this as well for ‘Prune stale remote-tracking branches’.

    Git Baby is a git and github fan, let's start git clone.