Windows Agent does not want to stay active

I have two Windows 10 machines on which I want to run the agent. The first machine works without problems, but on the second machine the agent does not want to stay active.

I have set up the start of the agent via a batch in the task scheduler. On the first machine the batch starts when the machine is started, on the second machine the batch is also started, but is immediately closed as successful again. (action “C:\Windows\SYSTEM32\cmd.exe” with return code 0.)

Does anyone know this phenomenon? The machines are set up identically and also the tasks in the scheduler are set up identically.

1 Like

Have you checked the logs on the agent that is not working? It should be in the working directory setup in the agent config in the controller UI

1 Like

Unfortunately, there is no log.
I only have the message from the task scheduler that the task was successfully completed.
If I start the batch manually everything works. Only the Task Scheduler does not leave it open but simply closes it.
The batch is configured identically as on machine 1. Of course, the name and the secret key is adjusted.

That’s my Batch:
"C:\Program Files\Java\jdk-11\bin\java.exe" -jar "c:\jenkins\agent.jar" -jnlpUrl -secret @secret-file

1 Like

Is the scheduled task setup under the same user account on both machines? Does that user have write access to the C:\Jenkins directory?

yes to both. I’ve added the Tasks on both mashines with the same User-credentials.
The User is an Admin User and have full access on C:\Jenkins

What about Java version on each machine? You say there is not a log, but the scheduled task succeeds? Does your bat file exit /b %ERRORLEVEL% after the java line?

It might be good to join the gitter for jenkins, could get more realtime help.

  1. Add some echo steps before the java call and redirect them to a file. If the file exists you know that the batch is called properly.
  2. redirect the output of the java call to a log file. The task scheduler is not capturing the output so if there is a problem in starting up java itself you will never find out what the cause is.
echo "Starting Jenkins agent" > c:\jenkins\agent.log
"C:\Program Files\Java\jdk-11\bin\java.exe" -jar "c:\jenkins\agent.jar" -jnlpUrl  -secret @secret-file >> c:\jenkins\agent.log
1 Like

I’ve edited the batch and got a agent.log. But there ist only 1 Line:
“Starting Jenkins agent”

Even when I start the batch by hand.

I’ve deleted the first line “echo Start Jenkins…”, but the redirect to the log for the java line is still there.
When I restart the machine, the logfile will created but it is empty

Both machines are new and I installed the same Java-Version on both.

I’ve got it!

I made a complete new batch-file with the following content:

cd C:\jenkins\
java -jar agent.jar -jnlpUrl http://xxx:8082/manage/computer/WindowsAgent02/jenkins-agent.jnlp -secret a8...

This file starts with Task Scheduler and is still running.

Thanks a lot for your help.

1 Like

Thanks a lot for your feedback @Lokutus25 .