Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • That question does not answer my question: what are these files.
  • The answers to that question suggest using deleteDir, which is not recommended when using Docker containers.
like image 796
GluePear Avatar asked Oct 28 '19 09:10

GluePear


2 Answers

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.

like image 87
Viktor Be Avatar answered Oct 11 '22 01:10

Viktor Be


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.

like image 4
75ntamas Avatar answered Oct 11 '22 02:10

75ntamas