Hello

We have an old-style job where under "Inject environment variables to the build 
process"
a groovy script from "Evaluated Groovy script" is executed. It runs on the 
master but
creates a file to be placed in the workspace on the agent where the main work 
is done.
It runs on the master as we use several plugins installed in Jenkins.

I've now made a stage in my pipeline that runs on agent 'master'. However I now 
have
problems with starting the script itself:

        def sharedData = new Binding()
        def shell = new GroovyShell(this.class.getClassLoader(), sharedData)
        sharedData.setProperty('out', out)
        sharedData.setProperty('currentBuild', currentBuild)
        // read script file from node (executing on master)
        shell.evaluate(new InputStreamReader(new 
hudson.FilePath(currentBuild.getWorkspace(), 'script.groovy').read()))

But that gives an error that 'out' is not known. I replaced it with (might be 
wrong too):
        sharedData.setProperty("out", new StringWriter());

Now the script content is a problem as functions seem unknown or different:
script.groovy:
        thefile = new PrintWriter(new 
hudson.FilePath(currentBuild.getWorkspace(), file.txt').write())
        thefile.println(currentBuild.getProject().getDisplayName() + ' build ' 
+ currentBuild.getDisplayName())

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No 
signature of method: 
org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper.getWorkspace() is 
applicable for argument types: () values: []

Do I have to give a different parameter than 'currentBuild' that implements 
these
functions? Do I have to change the groovy script?

Thanks for any help.

bye   Fabi

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/20220421131243.3F8854B94A29%40macserver.private.

Reply via email to