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?

  • what permissions should jenkins have to execute shell-commands without being insecure?
  • include downstream/child Jenkins job's console output into triggering job's console output
  • How do I get a grunt task working with a Cloudbees Jenkins build
  • How to list the slowest JUnit tests in a multi-module Maven build
  • Maven with Jenkins - Update parent pom version of dependency
  • Variable from a property file used in email trigger script in JENKINS
  • Jenkins: could not create Android emulator failed to parse AVD config file
  • Jenkins GIT include regions never builds for
  • Jenkinsfile get current tag
  • Jenkins Groovy URL get parameter
  • How would I produce JUnit test report for groovy tests, suitable for consumption by Jenkins/Hudson?
  • jenkins do not send emails to multple recipients
  • 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') {

    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.