Jenkins windows slave service does not interact wi

2019-01-14 13:18发布

问题:

I have followed this guide to install a jenkins slave on windows 8 as a service:

https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service#InstallingJenkinsasaWindowsservice-InstallSlaveasaWindowsservice%28require.NET2.0framework%29

I need to run a job that interact with the desktop (run an application that opens a browser etc.). So after I have installed the slave as a service (running jnlp downloaded from the master) I have changed the service "Log on" to "Allow to interact with display".

For some reason its only possible to enable this for the "Local System account" even though its recommended to run the service as a specified user, eg. jenkins.

But nothing happens when I execute the job, the browser is not opened. If I instead stop the service and just launch the slave through the jnlp file the job runs fine - the browser is opened.

Anybody had any luck interacting with the desktop when running a jenkins windows slave as a service?

回答1:

Services run since Vista in Session 0 and the first user is now in Session 1. So you can't interact any longer. This is called Session 0 Isolation.

Microsoft explains this here and here. You have to use 2nd Program which uses IPC to communicate to the Service.



回答2:

To Solve it set Windows Auto Logon as I explain here: https://serverfault.com/questions/269832/windows-server-2008-automatic-user-logon-on-power-on/606130#606130

Then create a startup batch for Jenkins slave (place it in Jenkins directory), which will launch it's console on desktop, and will allow GUI jobs to run:

java -jar slave.jar -jnlpUrl http://{Your Jenkins Server}:8080/computer/{Your Jenkins Node}/slave-agent.jnlp

(the slave.jar you can download from http://{Your Jenkins Server}:8080/jnlpJars/slave.jar)

EDIT : If you're getting black screenshots (when using Selenium or Sikuli, for example), create a batch file that disconnects Remote Desktop, instead of closing the RDP session with the regular X button:

%windir%\system32\tscon.exe %SESSIONNAME% /dest:console 


回答3:

I had lots of issues running Jenkins in Windows using the service. Instead I now disable the service and run it from CMD.

So open CMD.

cd C:\Program Files (x86)\Jenkins

java -Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar
jenkins.war --httpPort=9091


回答4:

Consider running the Java slave server directly at startup and then using something to monitor and restart should the server go down (e.g., Kiwi Restarter).



回答5:

Please check the services (@ TestNode) make sure the "Interactive Services Detection" service is STARTED, by default the startup type is set to Manual, you may like to set it to automatic as well.

After service started, when you run your test in the Test Node, you will see something like the below:

Click on it and choose view the message

You will see the activities happen there. Hope this helps :D

Note: If login with other account and cannot view the Interative Services Detection prompt, restart the service again.



回答6:

My Jenkins Service runs as user "jenkins" and all I did was to create Desktop folders in: C:\Windows\system32\config\systemprofile\desktop and if 64 bit Windows also in C:\Windows\SysWOW64\config\systemprofile\desktop - then it runs perfectly.



回答7:

Make sure that Desktop folders are created as such:

  • %WINDOWS%/System32/config/systemprofile/Desktop
  • %WINDOWS%/SystemWOW64/config/systemprofile/Desktop

Presence of those can sometimes be mandatory while running some Java software as a Service.