Pipeline plugin - How do I find directories?

3,640 views
Skip to first unread message

Jonathan Hodgson

unread,
Oct 15, 2016, 8:06:35 AM10/15/16
to Jenkins Users
Hi,

I need to find all the folders with a given name which are in my workspace (well in fact I need to find their parent folders)

A quick test with findFiles indicates it only finds files, not folders.
Message has been deleted

Rachel

unread,
Oct 15, 2016, 12:55:53 PM10/15/16
to Jenkins Users
Hi Jonathan,

I think that utility is not available. Alternatively, it's possible to use find command (if Linux):

node {
   stage
'Create folders in workspace for showing'
   sh
'''#!/bin/bash +x
         mkdir -p my_folder1/my_subfolder_1.1/my_subfolder_1.1.1
         mkdir -p my_folder2/my_subfolder_2.1/
         mkdir -p my_folder3/my_subfolder_3.1/my_subfolder_3.1.1
         '''

   stage
'List folders'
   sh
'''#!/bin/bash +x
         for directory in `find $WORKSPACE -type d -name \'my_subfolder_?.?.?*\'`; do
             echo "$directory found, with parent: $(dirname $directory)"
         done'''

}


List folders stage output:


[workspace] Running shell script
./my_folder1/my_subfolder_1.1/my_subfolder_1.1.1 found, with parent: ./my_folder1/my_subfolder_1.1
./my_folder3/my_subfolder_3.1/my_subfolder_3.1.1 found, with parent: ./my_folder3/my_subfolder_3.1


I hope be useful.

Best regards,
Rachel

Baptiste Mathus

unread,
Oct 16, 2016, 2:17:46 AM10/16/16
to jenkins...@googlegroups.com

IIRC look in the pipeline-utility-steps plugin.

Cheers


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/aa307eba-f6c5-47e4-a1eb-cf5a46367101%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jonathan Hodgson

unread,
Oct 16, 2016, 7:54:54 AM10/16/16
to Jenkins Users, m...@batmat.net


On Sunday, October 16, 2016 at 7:17:46 AM UTC+1, Baptiste Mathus wrote:

IIRC look in the pipeline-utility-steps plugin.

Cheers



That's the FindFiles I already tried, which seems to find files, but not folders. 

Jonathan Hodgson

unread,
Oct 16, 2016, 7:56:21 AM10/16/16
to Jenkins Users


On Saturday, October 15, 2016 at 5:55:53 PM UTC+1, Rachel wrote:
Hi Jonathan,

I think that utility is not available. Alternatively, it's possible to use find command (if Linux):

node {
   stage
'Create folders in workspace for showing'
   sh
'''#!/bin/bash +x
         mkdir -p my_folder1/my_subfolder_1.1/my_subfolder_1.1.1
         mkdir -p my_folder2/my_subfolder_2.1/
         mkdir -p my_folder3/my_subfolder_3.1/my_subfolder_3.1.1
         '''

   stage
'List folders'
   sh
'''#!/bin/bash +x
         for directory in `find $WORKSPACE -type d -name \'my_subfolder_?.?.?*\'`; do
             echo "$directory found, with parent: $(dirname $directory)"
         done'''

}


List folders stage output:


[workspace] Running shell script
./my_folder1/my_subfolder_1.1/my_subfolder_1.1.1 found, with parent: ./my_folder1/my_subfolder_1.1
./my_folder3/my_subfolder_3.1/my_subfolder_3.1.1 found, with parent: ./my_folder3/my_subfolder_3.1


I hope be useful.



Thanks,

unfortunately I need a cross platform solution. I've not had much luck with running a shell under wimdows 

Rachel

unread,
Oct 16, 2016, 10:08:46 AM10/16/16
to Jenkins Users
Hi Jonathan,

Sorry. Firstly, I'll tried to write Groovy code for cross platform solution, but it seems there is a problem with Closure (https://issues.jenkins-ci.org/browse/JENKINS-26481) and methods like eachDirRecurse, eachFileMatch, ... don't work (they only iterate one time).

Best regards,
Rachel
Reply all
Reply to author
Forward
0 new messages