Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins pipeline - Remove @tmp folder

I am using "Workspace Cleanup Plugin" to clean workspace after the job finishes. But still @tmp directory is not deleted.

Any way we can delete this @tmp folder using pipeline script.

It looks like a known issue as far as I see in Jira:

  • https://issues.jenkins-ci.org/browse/JENKINS-44909
  • https://issues.jenkins-ci.org/browse/JENKINS-41805
like image 749
Pankaj Shinde Avatar asked Mar 22 '19 10:03

Pankaj Shinde


People also ask

What is @TMP folder Jenkins?

It [@tmp folder] contains the content of any library that was loaded at run time.

How do I delete a folder in Jenkins?

Delete views and folders - Jenkins Tutorial To delete a view, you would start by entering the view. And let's look at the build view for example. On the left-hand side, there is an option to delete view. So I'll click that and I'm prompted to confirm the deletion.

How do I delete a file in Jenkins pipeline?

Navigate to /scriptApproval/ (Manage Jenkins > In-process Script Approval) and approve the script. File. delete works on master.

How do I clean my Jenkins pipeline workspace?

Login to Jenkins, click on “Manage Jenkins” > “Manage Plugins” > Click on the “Available” tab then search for “workspace cleanup“. You will see various plugins listed. Click on the checkbox for “Workspace Cleanup“, plugin then click on install without reboot tab below the page.


3 Answers

I used custom workspace in Jenkins then deleteDir() will not delete @tmp folder.

So to delete @tmp along with workspace use following

pipeline {
    agent {
        node {
            customWorkspace "/home/jenkins/jenkins_workspace/${JOB_NAME}_${BUILD_NUMBER}"
        }
    }
    post {
        cleanup {
            /* clean up our workspace */
            deleteDir()
            /* clean up tmp directory */
            dir("${workspace}@tmp") {
                deleteDir()
            }
            /* clean up script directory */
            dir("${workspace}@script") {
                deleteDir()
            }
        }
    }
}

This snippet will work for default workspace also.

like image 68
Pankaj Shinde Avatar answered Sep 24 '22 03:09

Pankaj Shinde


You can use deleteDir() as the last step of the pipeline Jenkinsfile (assuming you didn't change the working directory).

like image 42
RUSLAN MELNIC Avatar answered Sep 22 '22 03:09

RUSLAN MELNIC


The following code snippet works great.

//@tmp clean up
stage ('cleanup') 
{
  withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']) {
  dir('<your directory path>') {
  sh "rm -rf <directory `enter code here`name>@tmp"
  }
  }
}
like image 43
MeowRude Avatar answered Sep 22 '22 03:09

MeowRude