1

I have a number of Jenkins pipeline and I would like to delete the directory when the pipeline finishes, (pass or fail).

I have added the following stage to all of my pipelines.

    post {
        always {
                step([$class: 'WsCleanup'])
        }
    }

This does work, but somewhere during the clean up it creates another folder in the same dir and makes it as ws-cleanup eg. myservices_ws-cleanup_1571049838662

Is it possible to delete the directory without creating the ws-cleanup directory?

user3292394
  • 609
  • 2
  • 11
  • 24

2 Answers2

1

your post looks more Jenkins declarative pipeline combined with scripted Jenkins pipeline

post {
    always {
       script {    
            step([$class: 'WsCleanup'])
       }
    }
}

if you want to combine this don't forget to use script block. And btw, when you start a job and if the job runs on Jenkins Slave then Jenkins will create a workdir with the job name specified in the Jenkins UI.

My understanding is if you will do a post condition on your pipelines with cleanWs() that will clean up the content inside the workspace folder, but not the entire folder... the folder-name will remain(empty).

That makes possible to start/test a fresh new/next Job on a fresh workspace.

Here is the answer to your question Check the answer

enkicoma
  • 461
  • 4
  • 25
0

Is not cleanWs() working for your purpose? If not you can always use the deleteDir() option

post {
    always {
            cleanWs()
    }
}
Guel135
  • 750
  • 7
  • 26