Search code examples
javajenkinsjenkins-pipeline

How to solve generic 'Unexpected error in launching an agent. This is probably a bug in Jenkins' error on Jenkins agent startup


I have configured a docker cloud dynamic agent creation with the following settings: cloud configuration and the agent config as follows: agent config

but they fail to start. Been googling around but since I have little to nothing to go on with the logs, I don't know how to fix this.

Connecting to docker container 2169d7b0f9de955c89916da421dc6e04f41104423d0fdcd28796162225cf491f, running command java -jar //remoting-4.11.2.jar -noReconnect -noKeepAlive -agentLog //agent.log
HTTP/1.1 101 UPGRADED
Content-Type: application/vnd.docker.raw-stream
Connection: Upgrade
Upgrade: tcp
Api-Version: 1.41
Docker-Experimental: false
Ostype: linux
Server: Docker/20.10.12 (linux)
ERROR: Unexpected error in launching an agent. This is probably a bug in Jenkins
Also:   java.lang.Throwable: launched here
    at hudson.slaves.SlaveComputer._connect(SlaveComputer.java:282)
    at hudson.model.Computer.connect(Computer.java:440)
    at hudson.slaves.SlaveComputer.doLaunchSlaveAgent(SlaveComputer.java:796)
    at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
    at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:393)
    at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:405)
    at org.kohsuke.stapler.interceptor.RequirePOST$Processor.invoke(RequirePOST.java:77)
    at org.kohsuke.stapler.PreInvokeInterceptedFunction.invoke(PreInvokeInterceptedFunction.java:26)
    at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:208)
    at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:141)
    at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:536)
    at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)

The last part of the logs stay:

java.io.EOFException: unexpected stream termination
    at hudson.remoting.ChannelBuilder.negotiate(ChannelBuilder.java:464)
    at hudson.remoting.ChannelBuilder.build(ChannelBuilder.java:409)
    at hudson.slaves.SlaveComputer.setChannel(SlaveComputer.java:432)
    at hudson.slaves.SlaveComputer.setChannel(SlaveComputer.java:399)
    at io.jenkins.docker.connector.DockerComputerAttachConnector$DockerAttachLauncher.launch(DockerComputerAttachConnector.java:321)
    at hudson.slaves.DelegatingComputerLauncher.launch(DelegatingComputerLauncher.java:63)
    at io.jenkins.docker.connector.DockerDelegatingComputerLauncher.launch(DockerDelegatingComputerLauncher.java:37)
    at hudson.slaves.SlaveComputer.lambda$_connect$0(SlaveComputer.java:293)
    at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
    at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:80)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

and in jenkins logs I see:

96a29780b14e340c1667f2 for node Jenkins JDK11 agent-00000a8utz442 from image: jenkins/agent:alpine
2022-01-27 22:56:32.628+0000 [id=188]   INFO    i.j.d.c.DockerMultiplexedInputStream#readInternal: stderr from Jenkins JDK11 agent-00000a8utz442 (4611c8568d1b73e6a8b7e54613f7ef06c79210f03a96a29780b14e340c1667f2): Jan 27, 2022 10:56:32 PM org.jenkinsci.remoting.engine.WorkDirManager setupLogging
INFO: Using /agent.log as an agent error log destination; output log will not be generated
2022-01-27 22:56:32.628+0000 [id=188]   INFO    i.j.d.c.DockerMultiplexedInputStream#readInternal: stderr from Jenkins JDK11 agent-00000a8utz442 (4611c8568d1b73e6a8b7e54613f7ef06c79210f03a96a29780b14e340c1667f2): Exception in thread "main"
2022-01-27 22:56:32.629+0000 [id=188]   INFO    i.j.d.c.DockerMultiplexedInputStream#readInternal: stderr from Jenkins JDK11 agent-00000a8utz442 (4611c8568d1b73e6a8b7e54613f7ef06c79210f03a96a29780b14e340c1667f2): java.io.FileNotFoundException: /agent.log (Permission denied)
2022-01-27 22:56:32.629+0000 [id=188]   INFO    i.j.d.c.DockerMultiplexedInputStream#readInternal: stderr from Jenkins JDK11 agent-00000a8utz442 (4611c8568d1b73e6a8b7e54613f7ef06c79210f03a96a29780b14e340c1667f2):    at java.base/java.io.FileOutputStream.open0(Native Method)
2022-01-27 22:56:32.629+0000 [id=188]   INFO    i.j.d.c.DockerMultiplexedInputStream#readInternal: stderr from Jenkins JDK11 agent-00000a8utz442 (4611c8568d1b73e6a8b7e54613f7ef06c79210f03a96a29780b14e340c1667f2):    at java.base/java.io.FileOutputStream.open(Unknown Source)
2022-01-27 22:56:32.629+0000 [id=188]   INFO    i.j.d.c.DockerMultiplexedInputStream#readInternal: stderr from Jenkins JDK11 agent-00000a8utz442 (4611c8568d1b73e6a8b7e54613f7ef06c79210f03a96a29780b14e340c1667f2):    at java.base/java.io.FileOutputStream.<init>(Unknown Source)

Which is actually not that much info either.


Solution

  • In the agent configuration put /home/jenkins in the field Remote File System Root. I had the same problem and this fixed it for me.