At 15:12 21.04.2022, you wrote:

>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?

I found out that the groovy script execution under "Inject environment 
variables..."
is done using the "Environment Injector Plugin" which prepares these missing
variables like this:

currentJob
    Current hudson.model.Job instance.
currentBuild
    Current hudson.model.Run instance.
currentListener
    Current hudson.model.TaskListener instance, which can be used for logging 
purposes. 
out
    Another logging instance as java.io.PrintStream. It is recommended to use 
currentListener instead of this variable when possible. 

As I'm now executing my script directly I need to prepare these variables 
myself.
Can anybody help me to get to them? I tried to find this in the envinject plugin
source but I wasn't able to. I guess it should be pretty simple.

Thanks

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/20220422065903.437BF4B985C8%40macserver.private.

Reply via email to