4
votes

We are migrating from a legacy Jenkins setup to a new server where all plans are declarative jenkinsfile pipelines... however, by using pipelines, we can no longer manually clear the workspace. How do I set up Jenkins to allow manual on-demand clearing of the workspace?

I do not want the workspace cleared on every run - our horrible legacy app comes from a repo that's 1.7G in size (!) and takes forever to pull. Clearing on every run is not a workable option. I'd prefer not to follow the 'ssh in and delete the directory manually' option because not all Jenkins users have ssh access.

All the existing answers I've found have involved either "make it happen every time as part of the pipeline" or "run a script on the server" - surely there's a way in the Jenkins GUI to say "zap this workspace so we can build clean next time"?

(we can view the workspace with (buildnum) > Pipeline Steps > Allocate Node: Start > Workspace, but can't zap it there)

1

1 Answers

5
votes

You could add a parameter to the pipeline:

properties([
  parameters([
    string(name: 'cleanWorkspace', defaultValue: 'false')
  ])
])

Then in the pipeline, only trigger deleteDir() when the parameter is passed as true:

if(params.cleanWorkspace == 'true') {
    deleteDir()
}