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?

  • why does bitbucket branch project does checkout twice?
  • Pass Jenkins build parameters to pipeline nodes
  • Jenkins pipeline - git branch
  • Proper configuring of Multibranch Pipeline in Jenkins
  • How to know which user answered a Jenkins-Pipeline input step?
  • SparseCheckout in Jenkinsfile pipeline
  • Jenkins pipeline environment variables
  • How to obtain the folder where the Pipeline Jenkinsfile is checked out (Jenkins)
  • 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.