Reading all files from workspace

724 views
Skip to first unread message

Substance586

unread,
May 15, 2017, 12:10:41 PM5/15/17
to job-dsl-plugin
Hi, I've been working on a way to automatically create seed jobs for every job dsl script I have in my 'jobs' folder in my project .  The following code works as expected on my workstation but doesn't generate anything in Jenkins because it's not finding any files.

import static groovy.io.FileType.FILES

def dir = new File("jobs");
def files = [];
dir.traverse(type: FILES, maxDepth: 0) { files.add(it) };

files.each {
    // build seed job here
}

 I suspect it might be a security issue on my Jenkins box.  I've also tested this on both slaves and the master in case there's any confusion about where the workspace is but I've gotten the same results each time.

Andrew McLaughlin

unread,
May 15, 2017, 2:05:42 PM5/15/17
to job-dsl...@googlegroups.com
I have a similar Jenkins job that traverses a deep directory of files and builds a Jenkins job hierarchy tree for each. Works great and just as expected.

So, maybe your the files are missing in the repository? 

Are you building on Jenkins by tag? 

Are all the jobs files tagged the same so they will be visible?




--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/a300deb1-b535-4f85-ba14-7244fe64f082%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Substance586

unread,
May 16, 2017, 9:33:07 AM5/16/17
to job-dsl-plugin
Thanks for the reply Andrew!  All the files are present in the Jenkins job's workspace exactly how they are stored in Git.  I've tried it two ways too, one by pulling in a .groovy file from the workspace and another by running it as an inline script, same results both ways.  

|- jobs/
           |   |- job1.groovy
           |   |- job2.groovy
           |   |- etc... 
           |
|- resources/
|- src/
|- seeds/
|   |-seed_of_seeds.groovy  <- My seed job builder file
           | 
|- build.gradle
|- gradle.properties


Result:
Processing DSL script seed_of_seeds.groovy
files found: 0

Andrew McLaughlin

unread,
May 16, 2017, 1:32:45 PM5/16/17
to job-dsl...@googlegroups.com
Then perhaps your not in the directory you think you are. Maybe after you create the “dir” File object check the “absolutePath” and see what it reports.

File dir = new File(‘.’) // Currenty directory
println dir.absolutePath // Print the path of where we are running from...


Substance586

unread,
May 23, 2017, 9:26:54 AM5/23/17
to job-dsl-plugin
Great troubleshooting tip Andrew, that helped me solve the problem.  In my case, it turns out that I needed to set my path to "${WORKSPACE}/jobs" for Jenkins to pick up the right directory.  My only problem left is figuring out how to reconcile the path needed for Jenkins vs. the one needed for my 'gradle test' tasks to pass, which is a gradle issue instead of a job dsl one.  Thanks again for the help!

Andrew McLaughlin

unread,
May 23, 2017, 2:16:53 PM5/23/17
to job-dsl...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages