FilePath in Jenkinsfile

808 views
Skip to first unread message

Salvian Reynaldi

unread,
Aug 25, 2016, 12:31:24 AM8/25/16
to Jenkins Users
I had a bash script that push some directories to AWS S3

  for dir in */ ; do
   
"push.sh" "${dir::-1}"
 
done

assuming the current directory is X, the script will push ./a/ and ./b/ into s3://.../a/X and s3://.../b/X

Now i'm trying to switch to Jenkinsfile. To traverse child directories (like what the for loop basically did), the only method I found is using FilePath.listDirectories.
But how do I create a FilePath object? available constructors need another Filepath / channel. How can I achieve this?

Thanks

Salvian Reynaldi

unread,
Aug 25, 2016, 12:36:04 AM8/25/16
to Jenkins Users
P.S. I tried
def currentChannel = env.build.workspace channel, and gets
"No such property: build for class: groovy.lang.Binding" error

any help towards the goal (list child directories) would be appreciated

jer...@bodycad.com

unread,
Aug 25, 2016, 1:48:30 PM8/25/16
to Jenkins Users
Not sure if you need recursion or not but:

new File(".").eachDir() { it -> println it.getAbsolutePath() }
new File(".").eachFileRecurse() { it -> println it.getAbsolutePath() }

I had many problem with iterator into JenkinsFile where only the first match ever get executed. But if your bash script work you still can leave it there and simply call it with 
sh "myscript.sh"




jer...@bodycad.com

unread,
Aug 25, 2016, 1:56:25 PM8/25/16
to Jenkins Users
See this link for more file manipulation with groovy:

Salvian Reynaldi

unread,
Aug 25, 2016, 10:59:04 PM8/25/16
to Jenkins Users
No need for recursion :)
Actually I tried using new File() firstly, but Jenkins sandbox seems prevent calling to new File() (and new DateTime(), etc.)
Moreover, as the docs for FilePath says:
Unlike File, which always implies a file path on the current computer, FilePath represents a file path on a specific agent or the master
I assume using FilePath is preferred
Reply all
Reply to author
Forward
0 new messages