dockerjenkinsjenkins-pipeline

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


I have a Jenkins pipeline, for a PHP project in a Docker container. This is my Jenkinsfile:

pipeline {
  agent any
  stages {
    stage('Build') {
      agent any
      steps {
        sh 'docker-compose up -d'
        sh 'docker exec symfony composer install'
      }
    }
    stage('Test') {
      steps {
        sh 'docker exec symfony php ./bin/phpunit --coverage-clover=\'reports/coverage/coverage.xml\' --coverage-html=\'reports/coverage\' --coverage-crap4j=\'reports/crap4j.xml\''
      }
    }
    stage('Coverage') {
      steps {
        step([$class: 'CloverPublisher', cloverReportDir: '/reports/coverage', cloverReportFileName: 'coverage.xml'])
      }
    }
  }  
  post {
    cleanup {
      sh 'docker-compose down -v'
      cleanWs()
    }
  }
}

After running the pipeline, the var/lib/jenkins/workspace folder contains 4 folders (assuming my project name is Foo):

  1. Foo
  2. Foo@2
  3. Foo@2@tmp
  4. Foo@tmp

What are these, and how do I clean them up? cleanWs does not remove any except the first of them after the build.

EDIT: This is not a duplicate of this question because


Solution

  • 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.