0

I have been trying to automate workspace cleanup in jenkins, in which we need to retain the content upto certain number of days, lets say 'x', and need to delete the content older than x days.

I wrote a pipeline, which was rejected by unix team as they don't want to use rm -f INSTEAD they want to use cleanWS in the pipeline. The plugin is already installed in jenkins. Please suggest how can I use this plugin in the declarative pipeline to obtain the desired output. Jenkins version - 2.289.3

The pipeline which I wrote earlier, is as below:

Pipeline{
  agent{
     label "${params.agent}"
  }
  stages{
    stage('workspace cleanup'){
      steps{
        script{
           sh "find /jenkins/${params.folder} -mtime +${params.days} -exec rm -f {} \;"
        }
      }
    }
  }
}

1 Answers1

0

The Workspace Cleanup plugin is for removing files before or after a build. It runs within the context of a build.

In and of itself it does not have configuration regarding scheduling (clean files in a workspace every x days). From what I could see in the documentation the configuration relates to what it will delete AFTER a build is kicked off.

Good news is Jenkins is a job scheduler.

Bad news is (and I found this when I wanted to delete a particular workspace) it operates only on the workspace of the job it is running in. So I had to follow the steps I talked about here.

As much as it pains me to say it, Jenkins imo is dead. GitHub Actions is the future. All my open source is there now. SO much better. Convention over configuration. Companies don't want a Jenkins server work of art anymore. I would never go back.

Andrew Gray
  • 3,593
  • 3
  • 35
  • 62