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

File.eachFileRecurse(FileType.FILES) and File.eachDirRecurse() only loops for first element

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • workflow-cps-plugin
    • None
    • Jenkins ver. 2.77
      Pipeline: Groovy ver. 2.39
      Windows Server 2012 R2
      Java: Java(TM) SE Runtime Environment, 1.8.0_66-b18
      JVM: Java HotSpot(TM) Client VM, 25.66-b18, mixed mode

      Problem

      Both methods File.eachFileRecurse(FileType.FILES) and File.eachDirRecurse() only call the closure with the first element.

      Example pipeline script

      (I run this without groovy sandbox)

      import groovy.io.FileType
      
      node {
      	stage('test') {
      		def tmpDirPath = "C:\\temp\\test"
      		def tmpDir = new File(tmpDirPath)
      		
      		// Create test folders
      		new File(tmpDirPath+"\\dir1\\dir11\\dir111").mkdirs()
      		new File(tmpDirPath+"\\dir1\\dir12").mkdirs()
      		new File(tmpDirPath+"\\dir2\\dir21").mkdirs()
      		new File(tmpDirPath+"\\dir2\\dir22").mkdirs()
      		new File(tmpDirPath+"\\dir3").mkdirs()
      		
      		// Create test files
      		new File(tmpDirPath+"\\dir1\\dir11\\dir111\\file111") << "dummy"
      		new File(tmpDirPath+"\\dir1\\dir11\\file11") << "dummy"
      		new File(tmpDirPath+"\\dir1\\dir12\\file12") << "dummy"
      		new File(tmpDirPath+"\\dir2\\dir21\\file21") << "dummy"
      		new File(tmpDirPath+"\\dir2\\dir22\\file22") << "dummy"
      		new File(tmpDirPath+"\\dir3\\file3") << "dummy"
      		
      		// Output what eachDirRecurse does
      		tmpDir.eachDirRecurse() { dir ->
      			echo "Dir: ${dir}"
      		}
      		
      		// Output what eachFileRecurse does
      		tmpDir.eachFileRecurse(FileType.FILES) { file ->
      			echo "File: ${file}"
      		}
      	}
      }
      

      Output

      [Pipeline] node
      Running on master in C:\Program Files (x86)\Jenkins\workspace\Support\test
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (test)
      [Pipeline] echo
      Dir: C:\temp\test\dir1
      [Pipeline] echo
      File: C:\temp\test\dir1\dir11\dir111\file111
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

            Unassigned Unassigned
            swsbb Benjamin Buchfink
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: