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

Cleanup not working on build failure

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: ws-cleanup-plugin
    • Labels:
      None
    • Environment:
      centos7
      ws-cleanup 0.34
      jenkins 2.129
    • Similar Issues:

      Description

      Workspace is not being deleted on a failed build.
      If cleanWs() is at the end and build fails on steps before, cleanWs is not run.

      To reproduce:

      node('master'){
          sh 'ls -la'
          touch file: 'bla.txt'
          sh 'lsa -la'
          cleanWs()
      }
      

      Also tried with cleanWs cleanWhenFailure: true but it also does not work.

      Additionally, IMO, cleanWs() should be able to be called on any step of the pipeline and only triggered at the end of the build, accordingly to the build status setup in the pipeline.

      When setup at the beginning, it seems to clean the workspace immediately.

      Did not see any errors on logger, with log level ALL.

        Attachments

          Activity

          Hide
          ncosta Nuno Costa added a comment -

          Oleg Nenashev, thanks to point out that documentation. Although it is for a different plugin, it provides a useful example in this case.

          I assumed that the usage of cleanWs() had this try block behaviour already implied.
          Without it, IMO, I don't see much use on having the failure option there.

          Show
          ncosta Nuno Costa added a comment - Oleg Nenashev , thanks to point out that documentation. Although it is for a different plugin, it provides a useful example in this case. I assumed that the usage of cleanWs() had this try block behaviour already implied. Without it, IMO, I don't see much use on having the failure option there.
          Hide
          oleg_nenashev Oleg Nenashev added a comment -

          The described behavior is not a bug. Since a build step is used, it will be never called if previous steps fail. You could use the following script:

          node('master'){
              try {
                sh 'ls -la'
                touch file: 'bla.txt'
                sh 'lsa -la'
              } finally {
                cleanWs()
              }
          }
          

          Some documentation can be found here: https://github.com/jenkinsci/external-workspace-manager-plugin/blob/master/doc/WORKSPACE_CLEANUP.md

          But generally it would be great to have a new closure with automatic cleanup for Pipeline.

          Show
          oleg_nenashev Oleg Nenashev added a comment - The described behavior is not a bug. Since a build step is used, it will be never called if previous steps fail. You could use the following script: node( 'master' ){ try { sh 'ls -la' touch file: 'bla.txt' sh 'lsa -la' } finally { cleanWs() } } Some documentation can be found here: https://github.com/jenkinsci/external-workspace-manager-plugin/blob/master/doc/WORKSPACE_CLEANUP.md But generally it would be great to have a new closure with automatic cleanup for Pipeline.

            People

            Assignee:
            olivergondza Oliver Gond┼ża
            Reporter:
            ncosta Nuno Costa
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: