Why the agent doesn't work on Windows?

Hi all,

I have some troubles to make the agent run. I’m running the agent on Windows. The agent configuration is the following:
Name: agent1
Number of executors: 1
Remote root directory: C:\Users\user\jenkins-agent
Labels: pythonCookies (same name as the task)
Usage: Only build jobs with labels expressions matching this node
Launch method: Launch agent by connecting it to the controller
Enable Disable WorkDir
Internal data directory: remoting
Enable Use WebSocket
Availability: Keep this agent online as much as possible

Inside C:\Users\user\jenkins-agent I do have the following files (after executing jenkins-agent.exe in cmd administrator):
image

The configuration of the jenkins-agent.xml file is:

<service>    
	<id>jenkins8080agent</id>
	<name>Jenkins Agent for jenkins:8080</name>
	<description>This service is a service created from a minimal configuration</description>
	<executable>C:\Program Files\Java\jdk-17\bin\java.exe</executable>	
        <argument>-jar C:\Users\user\jenkins-agent\agent.jar -jnlpUrl http://localhost:8080/rparada/manage/computer/agent1/jenkins-agent.jnlp -secret 634e49160f5806a9f17fcb0dc97c98d78b8bcecb3cdf3e518cfed4c5398d5d3</argument>
        <log mode="roll" />
	<onfailure action="restart" />
</service>

However, I get this error:

Unrecognized option: -jar C:\Users\user\jenkins-agent\agent.jar -jnlpUrl http://localhost:8080/rparada/manage/computer/agent1/jenkins-agent.jnlp -secret 634e49160f5806a9f17fcb0dc97c98d78b8bcecb3cdf3e518cfed4c5398d5d3
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

If I try to access through the following link:
http://localhost:8080/rparada/manage/computer/agent1/jenkins-agent.jnlp?encrypt=true

I get this error:

I’ve been following this video How to Install Jenkins Agent on Windows - YouTube

Unfortunately, I cannot make it work.
Please, I would like some guidance.
Thanks

Two, three things are, as a noob, are not clear enough to me.

Java is reporting an error. I would first check, is java jre really able to run on that machine?

Can you open CMD and enter “C:\Program Files\Java\jdk-17\bin\java.exe -jar C:\Users\user\jenkins-agent\agent.jar” and watch the output, maybe there is some hint.

Second: You are on the agent, and you open a browser on the desktop and go to localhost:8080 ?
The URI mention something with rparada. But you are calling files from a user called user.
So i would think the URI maybe looks like user … Only the rparada account was renamed to user or the other way around, but that’s maybe no problem.

You are logged in as user or rparada? Maybe a rights problem?

I got:

WARNING: Are you running agent from an interactive console?
If so, you are probably using it incorrectly.
See https://wiki.jenkins.io/display/JENKINS/Launching+agent+from+console
<===[JENKINS REMOTING CAPACITY]===>rO0ABXNyABpodWRzb24ucmVtb3RpbmcuQ2FwYWJpbGl0eQAAAAAAAAABAgABSgAEbWFza3hwAAAAAAAAAf4=

How do I open a browser from the agent? Currently, I access the agent from localhost:8080 (browser). I’m logged to the system as user and inside jenkins as rparada. Should I change my username in jenkins to match the user of my system?

Ah, i see. That’s what i was not sure about. No, you don’t have to rename anything, but you have to check two things:

With linux you have some options, via ssh or a desktop remote program, so you can access a remote system from another machine. With two Windows machines, you can install putty with ssh capabilities as command line interface, or the windows own remote service, quick help, remote desktop, or Teamviewer, if you need a gui for setting things up.

But you need the login and password to the machine, to access this from another machine.

Check two things. (And this is not a professional way, but to be sure, that the two parts are working before heading on)

If you go to the machine physically, log in as user and take the instructions from the wiki, or use TeamViewer or the windows own programs as mentioned, and take the same wiki instructions.
Now you now (java is installed on the node and is running, because you got this message) that the jar file is running, which enables the node as jenkins node.

Second:
Can you access the node from outside, from another machine? Is there something you have to do, firewall etc. that you can get access from another machine?

But be careful, don’t open something to the world, that don’t had to be accessed from outside. Therefore ask your administrator.

Usually setting up a Jenkins node under Windows or Linux doesn’t make such problems.
I know the linux way, but only had a master under Windows running. I have to test this on my own.

And you have two different machines, right?

I was wondering if it is easier to run it on a VM with Linux or in a docker, I could have some firewall constrains. In the video looks so easier, however, in my case looks difficult even following all the steps.

I you want to get experience with a new program or system, a VM can be a choice.
But if you want to use Jenkins in production, you need power from different machines, and not the additional power drain from a VM on the same system.

If you run your Jenkins on one machine, you don’t need to set up agent on this system. Jenkins, the master node, can run jobs. But that’s mentioned everywhere, don’t run jobs on the master node. Because usually you need the power, ram, other resources from more than one machine.

I will setup a Windows 10 system with the latest Jenkins and an real Windows 10 agent over the weekend, and see, where are the caveats are.

Great! Thank you for the support.

Cheers, the error message as worded suggests to me that the whole argument string was provided to JVM as a single token (not as many tokens originally separated by spaces), so it does not know an argument by that huge name.

windows-slave-installer-module/jenkins-slave.xml at 47fc47c5b595446c1ee60793644ca9d64186d471 · jenkinsci/windows-slave-installer-module · GitHub suggests there is an arguments tag at same XML level as executable - try moving (and renaming) yours there.

UPDATE: not “moving”, your indentation was misleading. Just rename it.

Thanks. I have indented the lines correctly, as the link you’ve provided me. Now, I get this error:

Failed to obtain http://localhost:8080/rparada/manage/computer/agent1/jenkins-agent.jnlp?encrypt=true
java.io.IOException: Failed to load http://localhost:8080/rparada/manage/computer/agent1/jenkins-agent.jnlp?encrypt=true: 403 Forbidden
	at hudson.remoting.Launcher.parseJnlpArguments(Launcher.java:514)
	at hudson.remoting.Launcher.run(Launcher.java:346)
	at hudson.remoting.Launcher.main(Launcher.java:297)
Waiting 10 seconds before retry

That looks like a permissions error (says so on the tin) - check your Jenkins Controller security settings, whether JNLP is enabled, whether it needs auth, of which type etc. Maybe server logs would show more hints.

For example, in one server I have, its (Jenkins swarm) agents need to be pre-configured with a GitHub account and a token issued by GitHub (in lieu of password, may have several tokens per account for each different agent) because all accounts of that server must be github-backed per auth realm settings. In a private server on a LAN some internally-defined accounts or plain tokens might be usable (still, if not deprecated yet).

Where can I find the JNLP option? In Configure Global Security/Authentication in Security Realm I have "Jenkins’ own user database and Authorization “Anyone can do anything”. Is this the right way?

Looking at that setup now…

I think one thing changed to help the clients connect was using a static (fixed) port number in " Agents / TCP port for inbound agents" so it would be open on the firewall. Likewise for SSHD port for good measure.

Currently there is just one protocol to set up (v4 with TLS encryption); earlier there were older ones in the list. Make sure your agent trying to connect is recent enough.

Hm, my memory must have failed me about JNLP, can’t find anything about it in UI config nor in Java CLI options now.

Jim

I would like to setup a fixed TCP port for the agent service, however, I don’t know how to find the correct one. By cheking “netstat -ano -p tcp”

If I setup the fix TCP port to 56162 (just thinking is this one) I get this error:

Failed to listen to incoming agent connections
java.net.BindException: Address already in use: bind
	at java.base/sun.nio.ch.Net.bind0(Native Method)
	at java.base/sun.nio.ch.Net.bind(Net.java:555)
	at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337)
	at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294)
	at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:89)
	at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:81)
	at hudson.TcpSlaveAgentListener.createSocket(TcpSlaveAgentListener.java:108)
Caused: java.net.BindException: Failed to listen on port 8080 because it's already in use.
	at hudson.TcpSlaveAgentListener.createSocket(TcpSlaveAgentListener.java:110)
	at hudson.TcpSlaveAgentListener.<init>(TcpSlaveAgentListener.java:94)
	at jenkins.model.Jenkins.launchTcpSlaveAgentListener(Jenkins.java:1340)
	at jenkins.model.Jenkins.forceSetSlaveAgentPort(Jenkins.java:1242)
	at jenkins.model.Jenkins.setSlaveAgentPort(Jenkins.java:1236)
	at hudson.security.GlobalSecurityConfiguration.configure(GlobalSecurityConfiguration.java:147)
	at hudson.security.GlobalSecurityConfiguration.doConfigure(GlobalSecurityConfiguration.java:116)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:397)
	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:409)
	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:207)
	at org.kohsuke.stapler.SelectionInterceptedFunction$Adapter.invoke(SelectionInterceptedFunction.java:36)
	at org.kohsuke.stapler.verb.HttpVerbInterceptor.invoke(HttpVerbInterceptor.java:48)
	at org.kohsuke.stapler.SelectionInterceptedFunction.bindAndInvoke(SelectionInterceptedFunction.java:26)
	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:140)
	at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:558)
	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:59)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:770)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:900)
	at org.kohsuke.stapler.MetaClass$9.dispatch(MetaClass.java:475)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:770)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:900)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:836)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:900)
	at org.kohsuke.stapler.MetaClass$9.dispatch(MetaClass.java:475)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:770)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:900)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:698)
	at org.kohsuke.stapler.Stapler.service(Stapler.java:248)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
	at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665)
	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:157)
	at jenkins.telemetry.impl.UserLanguages$AcceptLanguageFilter.doFilter(UserLanguages.java:129)
	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:154)
	at jenkins.security.ResourceDomainFilter.doFilter(ResourceDomainFilter.java:81)
	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:154)
	at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:160)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:154)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:94)
	at jenkins.security.AcegiSecurityExceptionFilter.doFilter(AcegiSecurityExceptionFilter.java:52)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:54)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:126)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:120)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:100)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:145)
	at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:101)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:227)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:221)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at jenkins.security.BasicHeaderProcessor.doFilter(BasicHeaderProcessor.java:97)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:117)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
	at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:63)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:99)
	at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:111)
	at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:172)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:53)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:86)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at jenkins.security.SuspiciousRequestFilter.doFilter(SuspiciousRequestFilter.java:38)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:549)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:223)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1570)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1383)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1543)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1305)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at org.eclipse.jetty.server.Server.handle(Server.java:563)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:416)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:385)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:272)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.lambda$new$0(AdaptiveExecutionStrategy.java:140)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:411)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:934)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1078)
	at java.base/java.lang.Thread.run(Thread.java:833)

Unfortunately, I don’t have admin permissions to modify the firewall rules. The agent was setup just two weeks ago.

That looks like you are starting it to listen on a port that is already occupied by some process at that time.

Here it seems to be a client port like that of your browser or agent (client taking a random free port 56162 connected to server on 8080). Try using one that is actually not “LISTENING” nor “ESTABLISHED”, e.g. 8081.

Jenkins Swarm agents at least might use the newer websockets tech, to get the agent connection over same HTTP port as the usual server. Maybe that is another option to try (specifically easier for port-based firewall traversal).