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

Delete workspace before build starts ignores Exlude patterns (for directories)

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • ws-cleanup-plugin

      I need to exclude some directories from being deleted on workspace cleanup. It always deleted the entire workspace, pattern is always ignored.
      I used several combinations: */DIRNAME/., DIRNAME/., DIRNAME, *DIRNAME with or without checking "Apply pattern also on directories"

          [JENKINS-12783] Delete workspace before build starts ignores Exlude patterns (for directories)

          Voiculescu Bogdan Alexandru created issue -

          vjuranek added a comment -

          Hi,
          I cannot reproduce it (to be more specific, DIRNAME/** keeps DIRNAME and all files in it, DIRNAME keeps only this directory, no matter if "apply to directories" is switched on or off). Do you still have this issue?

          vjuranek added a comment - Hi, I cannot reproduce it (to be more specific, DIRNAME/** keeps DIRNAME and all files in it, DIRNAME keeps only this directory, no matter if "apply to directories" is switched on or off). Do you still have this issue?

          Rando Õispuu added a comment -

          When "Apply pattern also on directories" everything gets deleted regardless of the Exclude pattern. I use **/DIR/DIR/ it works when "Apply pattern also on directories" is not checked.

          Rando Õispuu added a comment - When "Apply pattern also on directories" everything gets deleted regardless of the Exclude pattern. I use **/DIR/DIR/ it works when "Apply pattern also on directories" is not checked.
          vjuranek made changes -
          Assignee Original: vjuranek [ vjuranek ] New: Lucie Votypkova [ lvotypkova ]

          I'm having the same issue. I have a workspace with "foo" and "bar" directories. I check the checkbox for "Delete workspace before build starts", and then underneath I add a directory and specify "Exclude" and then "foo". I also check the checkbox for "Apply patterns on directories". Then when I run my build, it cleans out BOTH the "foo" and "bar" directories. I would expect that it would delete "bar", but not "foo". But no matter what I specify for an "exclude", it always gets ignored.

          Justin Martenstein added a comment - I'm having the same issue. I have a workspace with "foo" and "bar" directories. I check the checkbox for "Delete workspace before build starts", and then underneath I add a directory and specify "Exclude" and then "foo". I also check the checkbox for "Apply patterns on directories". Then when I run my build, it cleans out BOTH the "foo" and "bar" directories. I would expect that it would delete "bar", but not "foo". But no matter what I specify for an "exclude", it always gets ignored.

          James Pace added a comment -

          I am also having issues with the exclude pattern. I do not want to delete a directory called "node_modules", or any of its sub directories or files, in the root of the workspace.

          I have added an exclude pattern "*/node_modules//" but it still gets deleted. It doesn't seem to matter if the delete directories checkbox is selected or not.

          James Pace added a comment - I am also having issues with the exclude pattern. I do not want to delete a directory called "node_modules", or any of its sub directories or files, in the root of the workspace. I have added an exclude pattern "* /node_modules/ / " but it still gets deleted. It doesn't seem to matter if the delete directories checkbox is selected or not.

          David Ackerman added a comment - - edited

          I had the same issue, and I think I figured out what was going wrong (after cloning the repo and adding enough logging statements).

          Excluding (not-deleting) everything under a toplevel directory works fine, i.e "toplevel/**" excludes everything under the folder "$WORKSPACE/toplevel". However, excluding something in a subdirectory does not work - i.e. "toplevel/asubdir/**" ends up deleting everything. This happens when you have "apply pattern also on directories" turned on. The reason is that DirectoryScanner will find directories to delete that might be parents of files that you've excluded, but the plugin deletes those folders recursively (i.e. rm -rf). The way to fix this is to add "toplevel" explicitly as an exclude to prevent it from deleting the parent directory as well. The reason I have the directories checkbox turned on is because I don't want the ".git" directory (or any extra directories) lying around and confusing jenkins when it builds the next time.

          My project looks something like this (in a multi-module maven project, where node_modules/ resides in several subdirectories).

          * folder-1
            - node_modules
          * folder-2
            - node_modules
          * folder-3
          * folder-4
            - node_modules
          

          My Configuration looks like this:

          EXCLUDE  **/node_modules/**
          EXCLUDE folder-1
          EXCLUDE folder-2
          EXCLUDE folder-4
          

          And that seems to work as expected. It seems like the plugin needs to be more careful about the directories it deletes recursively - it needs to avoid deleting a parent that would delete excluded files (or maybe just do "rm" instead of "rm -r" so it won't delete the directory if it has otherwise excluded files in it). I would offer to create a patch, but my Intellij doesn't seem to be resolving dependencies in the project properly (although maven commands work fine), and I am not sure what others would consider the ideal behavior. At the very least, I think more documentation in the plugin help and/or plugin page would save people a lot of time.

          David Ackerman added a comment - - edited I had the same issue, and I think I figured out what was going wrong (after cloning the repo and adding enough logging statements). Excluding (not-deleting) everything under a toplevel directory works fine, i.e "toplevel/**" excludes everything under the folder "$WORKSPACE/toplevel". However, excluding something in a subdirectory does not work - i.e. "toplevel/asubdir/**" ends up deleting everything. This happens when you have "apply pattern also on directories" turned on. The reason is that DirectoryScanner will find directories to delete that might be parents of files that you've excluded, but the plugin deletes those folders recursively (i.e. rm -rf). The way to fix this is to add "toplevel" explicitly as an exclude to prevent it from deleting the parent directory as well. The reason I have the directories checkbox turned on is because I don't want the ".git" directory (or any extra directories) lying around and confusing jenkins when it builds the next time. My project looks something like this (in a multi-module maven project, where node_modules/ resides in several subdirectories). * folder-1 - node_modules * folder-2 - node_modules * folder-3 * folder-4 - node_modules My Configuration looks like this: EXCLUDE **/node_modules/** EXCLUDE folder-1 EXCLUDE folder-2 EXCLUDE folder-4 And that seems to work as expected. It seems like the plugin needs to be more careful about the directories it deletes recursively - it needs to avoid deleting a parent that would delete excluded files (or maybe just do "rm" instead of "rm -r" so it won't delete the directory if it has otherwise excluded files in it). I would offer to create a patch, but my Intellij doesn't seem to be resolving dependencies in the project properly (although maven commands work fine), and I am not sure what others would consider the ideal behavior. At the very least, I think more documentation in the plugin help and/or plugin page would save people a lot of time.
          O. phyTe made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          O. phyTe made changes -
          Status Original: In Progress [ 3 ] New: Open [ 1 ]

          Larry Sanders added a comment - - edited

          I spent quite a bit of time on this very issue (ironically, also trying to avoid the node penalty).

          Of course leaving empty directories laying around is problematic, specifically for .repository when using a private maven repository for your build.

          Larry Sanders added a comment - - edited I spent quite a bit of time on this very issue (ironically, also trying to avoid the node penalty). Of course leaving empty directories laying around is problematic, specifically for .repository when using a private maven repository for your build.

            olivergondza Oliver Gondža
            bavoiculescu Voiculescu Bogdan Alexandru
            Votes:
            8 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: