readFileFromWorkspace method not found

1,839 views
Skip to first unread message

misha

unread,
Apr 10, 2017, 4:24:23 AM4/10/17
to job-dsl-plugin
Hello!

I'm getting an error:
ERROR: (PrepareBuildPublish.groovy, line 42) No signature of method: javaposse.jobdsl.dsl.helpers.step.StepContext.readFileFromWorkspace() is applicable for argument types: (java.lang.String) values: [WorkspaceLocker.groovy]

in jenkins Process Job DSLs step when executing
main.groovy:

import models.*
import templates.*

import hudson.FilePath
import org.yaml.snakeyaml.Yaml

createJobs
()

void createJobs() {
   
def yaml = new Yaml()

   
// Build a list of all config files ending in .yml
    def cwd = hudson.model.Executor.currentExecutor().getCurrentWorkspace().absolutize()
   
def configFiles = new FilePath(cwd, 'ci-repos').list('*.yml')

   
//for each config create a job
    configFiles.each { file ->
       
def projectConfig = yaml.loadAs(file.readToString(), ProjectConfig.class)
       
def project = projectConfig.project.replaceAll(' ', '-')

       
PrepareBuildPublish.create(job("${project}-Prepare-Build-Publish"), projectConfig)
   
}
}

PrepareBuildPublish.groovy source (I removed irrelevant configuration blocks from it):

package templates

class PrepareBuildPublish {
   
static void create(job, config) {
        job
.with {            
            steps
{
                systemGroovyCommand
(readFileFromWorkspace('WorkspaceLocker.groovy')){
                    binding
('repo','${config.repo}')
                    classpath
()
               
}
           
}
       
}
   
}
}


Please help understand why
readFileFromWorkspace method is not found, what needs to be imported and where ?
This code snippet worked when I used it directly in Jenkins Process Job DSLs plugin directly as a DSL script.

Thank you in advance

Victor Martinez

unread,
Apr 11, 2017, 12:41:29 PM4/11/17
to job-dsl-plugin

Daniel Spilker

unread,
Apr 11, 2017, 3:00:26 PM4/11/17
to job-dsl...@googlegroups.com
This has also been asked on Stack Overflow: http://stackoverflow.com/q/43320238/1271460


--
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-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/b90b12c1-dec7-4112-b8a9-447fb36ffa08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

misha

unread,
Apr 18, 2017, 4:59:56 AM4/18/17
to job-dsl-plugin
Thanks for pointing me to the similar topic, it looks promising, I'll give it a try, meanwhile I used this syntagma to run the groovy script, which requires script to be checked with each slave it runs, but it works.

steps {
systemGroovyScriptFile('WorkspaceLocker.groovy'){
binding('workdir',"${config.workdir}")
}
}

misha

unread,
Apr 21, 2017, 8:54:13 AM4/21/17
to job-dsl-plugin
I've tried Daniel's solution from https://groups.google.com/forum/m/#!topic/job-dsl-plugin/xsgWi2wOEx8 ( passing this (the script) to helper class ) and it worked for me, thank you Victor !

Reply all
Reply to author
Forward
0 new messages