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

EXCLUDE patterns can't protect directories included by "**"

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Consider the following pipeline code:

      void deleteOthers(List<String> pathList) {
      	def prefixes = []
      	for(path in pathList) {
      		def currentPrefix = path;
      		while(true) {
      			def prefixEnd = currentPrefix.lastIndexOf("/")
      			if(prefixEnd > 0) {
      				currentPrefix = currentPrefix.substring(0, prefixEnd);
      				prefixes.add(currentPrefix)
      			} else {
      				break;
      			}
      		}
      	}
      	prefixes.unique()
      	
      	def patterns = []
      	for(path in prefixes) {
      		patterns.add([
      			pattern: '/' + path,
      			type: 'EXCLUDE'
      		])
      	}
      	for(path in pathList) {
      		patterns.add([
      			pattern: '/' + path,
      			type: 'EXCLUDE'
      		])
      		patterns.add([
      			pattern: '/' + path + '/**',
      			type: 'EXCLUDE'
      		])
      	}
      	patterns.add([
      		pattern: '/**/*',
      		type: 'INCLUDE'
      	])
      	
      	
      	cleanWs deleteDirs: true, patterns: patterns
      	return
      }
      
      def keep = [
      	'foo',
      	'foo2',
      	'bar/foo',
      	'bar/foo2',
      	'bar/foo3/bla'
      ]
      for(path in keep) {
      	dir(path) {
      		writeFile file:'expected', text:''   
      	}
      }
      writeFile file:'unexpected', text:''
      writeFile file:'bar/unexpected', text:''
      writeFile file:'bar/foo3/unexpected', text:''
      deleteOthers(keep)
      

      Expected behavior:
      All the listed directories listed in "keep" are preserved (as both the directories themselves, as well as all parents are explicitly excluded!) and the included files are preserved.

      Only the files created outside of directories listed in "keep" are expected to be removed.

      Actual behavior:
      Only the directories + paths "foo/expected" and "foo2/expected" are preserved.
      All the directories with a nested paths, relative to include pattern, are impossible to preserve.

      It appears as if excludes fail to apply to any directory, if the directory was matched using a non-empty

      **

      part of the INCLUDE wildcard. Directories only matched by a single star, or an empty double-star have their EXCLUDE rules evaluated correctly.

      For files, excludes are properly evaluated even if the INCLUDE was matching with a non-empty double-star.

      E.g. with "deleteDirs: false", all expected files are protected correctly.

        Attachments

          Activity

          Hide
          basil Basil Crow added a comment -

          Hi Andreas Ringlstetter, thank you for providing detailed steps to reproduce this issue. Would you be interested in filing a PR to turn the above steps into an integration test, marked with @Issue("JENKINS-62044") and @Ignore? This would help get us closer toward releasing a fix. Let me know if I can answer any questions you might have along the way.

          Show
          basil Basil Crow added a comment - Hi Andreas Ringlstetter , thank you for providing detailed steps to reproduce this issue. Would you be interested in filing a PR to turn the above steps into an integration test, marked with @Issue(" JENKINS-62044 ") and @Ignore ? This would help get us closer toward releasing a fix. Let me know if I can answer any questions you might have along the way.

            People

            Assignee:
            olivergondza Oliver Gond┼ża
            Reporter:
            ext3h Andreas Ringlstetter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: