Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-41805

Pipeline Job-- deletedir() delete only current directory but @script and @tmp dir still there in workspace.

    • Jenkins 2.244

      Directories with an ampersand (like @tmp and @script, @libs) are not removed when using 'deletedir()' in pipeline stage.

      They are never cleaned up, even by the built in build discarders,
      On our instances we have 2172 folders with @libs (which is a copy of the shared library for the build)
      Which is taking up 7GB of space

          [JENKINS-41805] Pipeline Job-- deletedir() delete only current directory but @script and @tmp dir still there in workspace.

          Oleg Nenashev added a comment -

          timja Hi. Does https://www.jenkins.io/changelog/#v2.244 fully address it from your PoV?

          Oleg Nenashev added a comment - timja Hi. Does  https://www.jenkins.io/changelog/#v2.244  fully address it from your PoV?

          Tim Jacomb added a comment - - edited

          Yes I believe so,

          To any of the many watchers, from Jenkins 2.244 these directories will be automatically deleted during workspace cleanup.

          This retains workspaces for 30 days by default and then deletes them, I can't see any documentation on it, but the configuration values can be found here:
          https://www.jenkins.io/doc/book/managing/system-properties/#hudson-model-workspacecleanupthread-retainfordays

          Note: If the workspace has already been deleted then you'll need to delete existing libs / tmp / 2 directories manually

          Tim Jacomb added a comment - - edited Yes I believe so, To any of the many watchers, from Jenkins 2.244 these directories will be automatically deleted during workspace cleanup. This retains workspaces for 30 days by default and then deletes them, I can't see any documentation on it, but the configuration values can be found here: https://www.jenkins.io/doc/book/managing/system-properties/#hudson-model-workspacecleanupthread-retainfordays Note: If the workspace has already been deleted then you'll need to delete existing libs / tmp / 2 directories manually

          So how exactly is this used?  Does using deleteDir() clean out the entire workspace and associated "@" directories?  Is there any impact on cleanWs()?

          Camden Mamigonian added a comment - So how exactly is this used?  Does using deleteDir() clean out the entire workspace and associated "@" directories?  Is there any impact on cleanWs()?

          Tim Jacomb added a comment -

          cmamigonian does my comment above not explain it well enough?

          Jenkins core workspace cleanup will remove them, deleteDir doesn't do it and neither does cleanWs
          Possibly they could be extended to do it now that the core API is there.

          Tim Jacomb added a comment - cmamigonian does my comment above not explain it well enough? Jenkins core workspace cleanup will remove them, deleteDir doesn't do it and neither does cleanWs Possibly they could be extended to do it now that the core API is there.

          Yes, sorry, your comment is clear in terms of core cleanup.  I wasn't sure if deleteDir or cleanWs support it.  Do we know if those plugin(s) have plans to incorporate?

          Camden Mamigonian added a comment - Yes, sorry, your comment is clear in terms of core cleanup.  I wasn't sure if deleteDir or cleanWs support it.  Do we know if those plugin(s) have plans to incorporate?

          Tim Jacomb added a comment -

          Not that I know of, is there a reason that the automated cleanup isn't enough for you?

          Tim Jacomb added a comment - Not that I know of, is there a reason that the automated cleanup isn't enough for you?

          If we have lots of jobs running on an agent our storage can fill up quickly, and we like to clean up after ourselves once the pipeline is done running.  We currently have a way to do it, but it's through our own code instead of a much simpler single call to either cleanWs or deleteDir.

          Camden Mamigonian added a comment - If we have lots of jobs running on an agent our storage can fill up quickly, and we like to clean up after ourselves once the pipeline is done running.  We currently have a way to do it, but it's through our own code instead of a much simpler single call to either cleanWs or deleteDir.

          Naveen B added a comment -

          We are still seeing this issue in 2.277.1

          @tmp is left behind after

          {{}}

          dir('tst'){
              sh (
                  label : "ls",
                  script : "ls"
              )
              deleteDir()
          }

          {{}}

          Naveen B added a comment - We are still seeing this issue in 2.277.1 @tmp is left behind after {{}} dir( 'tst' ){ sh ( label : "ls" , script : "ls" ) deleteDir() } {{}}

          Tim Jacomb added a comment -

          The resolution was a background task that will remove them, deleteDir only deletes the current directory

          Tim Jacomb added a comment - The resolution was a background task that will remove them, deleteDir only deletes the current directory

          Jesse Glick added a comment -

          Yeah the Fixed resolution does not match the reported issue summary. deleteDir does exactly what it is documented to do: delete the contextual directory (which could be a subdirectory of the workspace, something else entirely, etc.), just like sh 'rm -rf .' basically.

          Jesse Glick added a comment - Yeah the Fixed resolution does not match the reported issue summary. deleteDir does exactly what it is documented to do: delete the contextual directory (which could be a subdirectory of the workspace, something else entirely, etc.), just like sh 'rm -rf .' basically.

            timja Tim Jacomb
            hiten_prajapati Hiten Prajapati
            Votes:
            67 Vote for this issue
            Watchers:
            91 Start watching this issue

              Created:
              Updated:
              Resolved: