What are the @tmp folders in a Jenkins workspace and how to clean them up

There is an opened Jenkins issue about deleteDir() not deleting the @tmp/@script/@... directories.

A workaround to delete those:

post {
  always {
    cleanWs()
    dir("${env.WORKSPACE}@tmp") {
      deleteDir()
    }
    dir("${env.WORKSPACE}@script") {
      deleteDir()
    }
    dir("${env.WORKSPACE}@script@tmp") {
      deleteDir()
    }
  }
}

There is also a comment on the issue describing what @tmp is:

It [@tmp folder] contains the content of any library that was loaded at run time. Without a copy, Replay can't work reliably.


The Foo@2 Foo@2@tmp folders were created because the agent was defined 2 times. Once it was defined at the top level inside the pipeline block. And once inside the stage called build. The working folder of stage 'build' is the Foo@2 folder.