jenkinsjenkins-plugins

How do I use the Jenkins workspace cleanup plugin?


I installed the https://wiki.jenkins-ci.org/display/JENKINS/Workspace+Cleanup+Plugin 0.46

I added to my jenkins pipeline:

post {
    // Clean after build
    always {
        cleanWs(cleanWhenNotBuilt: false, 
                deleteDirs: true,
                disableDeferredWipeout: true,
                notFailBuild: true,
                patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
                           [pattern: '.propsfile', type: 'EXCLUDE']])
    }
}

I see in my output:

[Pipeline] cleanWs
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is disabled by the job configuration...
[WS-CLEANUP] done

But when I log into my jenkins node and look at the workspace, all the files are still there. I've triggered a new build and I see the files get left behind as well


Solution

  • I simply used deleteDir() to clean up all files.

        always {
            // clean up workspace to get an clean build environment
            echo "CLEANUP WORKSPACE STARTED"
            deleteDir()
            echo "CLEANUP WORKSPACE FINISHED"
        }