-
Bug
-
Resolution: Not A Defect
-
Major
-
None
-
jenkins 2.361.2 (lts-jdk17), agent 3044.vb_940a_a_e4f72e, macOS Monterey 12.6, running jenkins master and agent in docker.
I have an "Execute system Groovy script" build step:
import hudson.FilePath import hudson.remoting.VirtualChannel import jenkins.MasterToSlaveFileCallable import java.nio.charset.StandardCharsets FilePath workspaceFilePath = build.getWorkspace() def patchTempFile = workspaceFilePath.createTempFile('foo', '.patch') try { println('Writing patch to temp file') def conn = (HttpURLConnection) new URL(build.environment.patchDownloadUrl).openConnection() int responseCode = conn.getResponseCode() if (responseCode == HttpURLConnection.HTTP_OK) { def contentDisposition = conn.getHeaderField("Content-Disposition") int index = contentDisposition.indexOf('filename=') if (index > 0) { filename = contentDisposition.substring(index + 10) } copyStream(conn.getInputStream(), patchTempFile.write()) } else { if (conn.getErrorStream() == null) { println "Failed to download patch file, response code: ${responseCode}" } else { def errorBaos = new ByteArrayOutputStream() copyStream(conn.getErrorStream(), errorBaos) def errorMessage = new String(errorBaos.toByteArray(), StandardCharsets.UTF_8) println "Failed to download patch file, response code: ${responseCode}, response body: ${errorMessage}" } return -1 } if (applyPatch(build.getWorkspace(), patchTempFile) != 0) { println 'Applying git patch failed!' return -1 } println('Applying patch using git') } finally { patchTempFile.delete() } static def applyPatch(FilePath workspaceFilePath, FilePath patchTempFilePath) { String command = "git apply ${patchTempFilePath.getName()}" patchTempFilePath.act(new MasterToSlaveFileCallable<Integer>() { @Override Integer invoke(File patchTempFile, VirtualChannel patchTempFileChannel) throws IOException, InterruptedException { println "executing ${command}" return workspaceFilePath.act(new MasterToSlaveFileCallable<Integer>() { @Override Integer invoke(File workspaceDir, VirtualChannel workspaceDirChannel) throws IOException, InterruptedException { def proc = command.execute(null, workspaceDir) def output = new StringWriter() def error = new StringWriter() proc.waitForProcessOutput(output, error) println("exit value: ${proc.exitValue()}") println("output: ${output}") println("err: ${error}") return proc.exitValue() } }) } }) } static def copyStream(InputStream inputStream, OutputStream outputStream) throws IOException { try { def byteCount = 0 byte[] buffer = new byte[4096] int bytesRead while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead) byteCount += bytesRead } outputStream.flush() return byteCount } finally { outputStream.close() inputStream.close() } }
This works when run on jenkins master, but fails when the build is run on a worker agent. Error message from build console output:
FATAL: Remote call on agent failed Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to channel at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784) at hudson.remoting.Request.call(Request.java:199) at hudson.remoting.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:288) at com.sun.proxy.$Proxy6.fetch3(Unknown Source) at hudson.remoting.RemoteClassLoader.prefetchClassReference(RemoteClassLoader.java:353) at hudson.remoting.RemoteClassLoader.loadWithMultiClassLoader(RemoteClassLoader.java:258) at hudson.remoting.RemoteClassLoader.findClass(RemoteClassLoader.java:228) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:398) at hudson.remoting.MultiClassLoaderSerializer$Input.resolveClass(MultiClassLoaderSerializer.java:132) at java.base/java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1995) at java.base/java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1862) at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2169) at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1679) at java.base/java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2464) at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2358) at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2196) at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1679) at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:493) at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:451) at hudson.remoting.UserRequest.deserialize(UserRequest.java:289) at hudson.remoting.UserRequest.perform(UserRequest.java:189) at hudson.remoting.UserRequest.perform(UserRequest.java:54) at hudson.remoting.Request$2.run(Request.java:376) at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829) java.lang.IllegalArgumentException: Unable to locate class file for class Script1$1 at hudson.remoting.Which.classFileUrl(Which.java:68) at hudson.remoting.RemoteClassLoader$ClassLoaderProxy.fetch4(RemoteClassLoader.java:1014) at hudson.remoting.RemoteClassLoader$ClassLoaderProxy.fetch3(RemoteClassLoader.java:1045) at jdk.internal.reflect.GeneratedMethodAccessor6.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:924) at hudson.remoting.Request$2.run(Request.java:376) at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78) at org.jenkinsci.remoting.CallableDecorator.call(CallableDecorator.java:18) at hudson.remoting.CallableDecoratorList.lambda$applyDecorator$0(CallableDecoratorList.java:19) at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:48) at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:82) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833) Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to agent at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784) at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356) at hudson.remoting.Channel.call(Channel.java:1000) at hudson.FilePath.act(FilePath.java:1186) at hudson.FilePath.act(FilePath.java:1175) at hudson.FilePath$act$1.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128) at Script1.applyPatch(Script1.groovy:46) at Script1$applyPatch$0.callStatic(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:197) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:217) at Script1.run(Script1.groovy:33) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:574) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:612) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:583) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:440) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:377) at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:95) at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:59) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:816) at hudson.model.Build$BuildExecution.build(Build.java:199) at hudson.model.Build$BuildExecution.doRun(Build.java:164) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:524) at hudson.model.Run.execute(Run.java:1899) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44) at hudson.model.ResourceController.execute(ResourceController.java:107) at hudson.model.Executor.run(Executor.java:449) Caused: java.lang.Error: Failed to deserialize the Callable object. at hudson.remoting.UserRequest.perform(UserRequest.java:195) at hudson.remoting.UserRequest.perform(UserRequest.java:54) at hudson.remoting.Request$2.run(Request.java:376) at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829) Caused: java.io.IOException: Remote call on agent failed at hudson.remoting.Channel.call(Channel.java:1004) at hudson.FilePath.act(FilePath.java:1186) at hudson.FilePath.act(FilePath.java:1175) at hudson.FilePath$act$1.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128) at Script1.applyPatch(Script1.groovy:46) at Script1$applyPatch$0.callStatic(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:197) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:217) at Script1.run(Script1.groovy:33) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:574) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:612) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:583) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:440) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:377) at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:95) at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:59) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:816) at hudson.model.Build$BuildExecution.build(Build.java:199) at hudson.model.Build$BuildExecution.doRun(Build.java:164) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:524) at hudson.model.Run.execute(Run.java:1899) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44) at hudson.model.ResourceController.execute(ResourceController.java:107) at hudson.model.Executor.run(Executor.java:449)
I've tried several different approaches to tweaking this code to get it to work and cannot find a way forward. What's wrong here?