Git Product home page Git Product logo

ws-cleanup-plugin's Introduction

Workspace Cleanup Plugin

Introduction

This plugin deletes the build workspace.

Getting started

There is a single step to be used whenever a workspace is allocated.

Declarative Pipeline

The cleanWs step is available for use with Declarative Pipeline. When you want to clean the workspace after the build, you can add this step under a suitable condition in the post section of your Pipeline job. If you want to clean the workspace before the build starts, you need to add some extra configuration to be able to clean before the sources are checked out from SCM. See the examples below for details.

The snippet generator that is built into Jenkins can assist you with what configuration options are available. Click on the Pipeline Syntax button in your Pipeline job and select cleanWs from the Sample Step drop-down. For example:

pipeline {
    agent any
    options {
        // This is required if you want to clean before build
        skipDefaultCheckout(true)
    }
    stages {
        stage('Build') {
            steps {
                // Clean before build
                cleanWs()
                // We need to explicitly checkout from SCM here
                checkout scm
                echo "Building ${env.JOB_NAME}..."
            }
        }
    }
    post {
        // Clean after build
        always {
            cleanWs(cleanWhenNotBuilt: false,
                    deleteDirs: true,
                    disableDeferredWipeout: true,
                    notFailBuild: true,
                    patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
                               [pattern: '.propsfile', type: 'EXCLUDE']])
        }
    }
}

Freestyle jobs

The plugin provides a build wrapper (Delete workspace before build starts) and a post build step (Delete workspace when build is done). These steps allow you to configure which files will be deleted and in what circumstances. The post build step can also take the build status into account.

This plugin also provides Job DSL support for Freestyle jobs. For example:

job("foo") {
    wrappers {
        preBuildCleanup { // Clean before build
            includePattern('**/target/**')
            deleteDirectories()
            cleanupParameter('CLEANUP')
        }
    }
    publishers {
        cleanWs { // Clean after build
            cleanWhenAborted(true)
            cleanWhenFailure(true)
            cleanWhenNotBuilt(false)
            cleanWhenSuccess(true)
            cleanWhenUnstable(true)
            deleteDirs(true)
            notFailBuild(true)
            disableDeferredWipeout(true)
            patterns {
                pattern {
                    type('EXCLUDE')
                    pattern('.propsfile')
                }
                pattern {
                    type('INCLUDE')
                    pattern('.gitignore')
                }
            }
        }
    }
}

Configuration

Patterns

ws cleanup

Files to be deleted are specified by pattern using Ant pattern syntax. You can choose if the pattern is an include pattern (if the file matches this pattern, the file will be removed) or exclude pattern (if the file matches this pattern, the file won’t be removed). If there is only an exclude pattern, **/* (i.e., delete everything) will be used as the include pattern, which means that everything will be deleted except the files matching the exclude pattern. Patterns are applied only on files; if you want to apply them also on directories, check the appropriate box.

⚠️
The directory is deleted with all its contents. If the directory matches the include pattern, everything in the directory will be deleted regardless as to whether some files in the directory match the exclude pattern.

See the documentation for the Ant DirectoryScanner class for examples of patterns.

Deferred wipeout

When the whole workspace is supposed to be deleted (no patterns, external commands, etc.), the Workspace Cleanup plugin delegates to the Resource Disposer plugin to speed things up.

When deferred wipeout is disabled, the old implementation of filesystem content deletion is used. If you want the same behavior as with deferred wipeout, you have to set the plugin attribute deleteDirs to true as well. For Pipeline jobs, you can do this as follows:

cleanWs disableDeferredWipeout: true, deleteDirs: true

For e.g. cloud developers it might be useful to be sure deferred wipeout is never selected as a cleanup method. Therefore there is a new feature introduced to do this, implemented via a regular NodeProperty which you can attach to any node via the UI or via a Groovy script as follows:

Node.getNodeProperties().add(new DisableDeferredWipeoutNodeProperty());

Issues

Report issues and enhancements in the Jenkins issue tracker. Use the ws-cleanup-plugin component in the JENKINS project.

Contributing

Refer to our contribution guidelines.

License

Licensed under the MIT License.

ws-cleanup-plugin's People

Contributors

alanharder avatar alexsomai avatar anusien avatar barretts avatar basil avatar daniel-beck-bot avatar darxriggs avatar dennisl avatar dependabot[bot] avatar dirvo avatar flozzone avatar ixdy avatar jebitok-dev avatar jorgenpt avatar jpsecher avatar kostyasha avatar lvotypko avatar mmitche avatar ndeloof avatar olivergondza avatar phoenix384 avatar pjanouse avatar slonopotamus avatar ssogabe avatar thomasherrlin avatar vjuranek avatar wernight avatar ydubreuil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.