36

I have a jenkins agent set up on window 7 and a jenkins server on Linux. I am running GUI testing on the windows agent. It runs fine if I have a remote desktop connection connected to it, but fails otherwise. I found this link, Jenkins on Windows and GUI Tests without RDC

But the solution provided there is pretty vague.. It seems like the only solution is to somehow make Jenkins server to have a remote desktop connection open at all times. But I can't find such an option to do so. Could anyone please clearly teach me how to solve this issue?

Much appreciated!

Community
  • 1
  • 1
Kelvin
  • 703
  • 1
  • 10
  • 13
  • Take a look at my answer here: http://stackoverflow.com/questions/10177708/jenkins-on-windows-and-gui-tests-without-rdc/20295828#20295828 – Andy Chen Nov 30 '13 at 02:38
  • @AndyChen Beside auto logon, I also needed this http://stackoverflow.com/a/24820786/1184842 – jan Jul 18 '14 at 08:45
  • 1
    It is true, every time I RDP to the VM, I restart it. Or you can log in only via VNC, then it doesn't need to restart. – Andy Chen Jul 22 '14 at 05:46

6 Answers6

27

Your slave machines have to be at a desktop before the test can run properly. We had the same problem.

Solution was to have the test machine start up and auto-logon to the desktop. To ensure that the test would ONLY start after the desktop was available, we added a scheduled task, set to run at user login, that would launch the Jenkins slave via Java Web Start. That way, Jenkins would only see the slave once the desktop was running. After that, everything worked fine.

This is the winning answer to the question you linked to and it is very clear on what to do. The whole setup is outside of Jenkins. Jason Swager discribed on how he automated a user logging into a windows desktop machine and then starting the Jenkins slave in the user session.

And now Step by step:

1. make sure you have a GUI evailable

Solution was to have the test machine start up and auto-logon to the desktop

Configure a standard Windows desktop to login a specific user automatically when windows start. This way nobody needs to physically log into the desktop. (see How to turn on automatic logon in Windows 7)

2. start Jenkins slave

You need to start the Jenkins slave within this user setting. Otherwise, the Jenkins slave won't have access to the Windows UI components (or in other words can not interact with the desktop).

To ensure that the test would ONLY start after the desktop was available, we added a scheduled task, set to run at user login, that would launch the Jenkins slave via Java Web Start.

So you have to create a scheduled task and configure it to start your Jenkins client using Java Web Start.

3. use it

That way, Jenkins would only see the slave once the desktop was running. After that, everything worked fine.

When the slave is online, you can use it to run your UI tests.

Community
  • 1
  • 1
Peter Schuetze
  • 16,185
  • 4
  • 44
  • 58
  • I believe I have done all of these - launch it via java web start, auto-logon the user (theres only one user, which is admin). But it still doesnt work without a RDC connection. – Kelvin Oct 18 '13 at 17:54
  • Does the system has a monitor connected to it? You need to have the UI components active and that is only if you have your jenkins client running under the same user then the user that is logged into the UI. – Peter Schuetze Oct 18 '13 at 18:49
  • No, the test machine is a virtual machine. It doesn't have a physical monitor connected to it. There is only one user under the windows slave, which is admin. So it shouldn't have any issues caused by multiple users, and I already enabled auto logon. – Kelvin Oct 18 '13 at 23:13
  • That might be your problem. Try the same setup with a physical machine and see if it works. If it does, it will be a strong indication, that you don't have the UI available when you don't have an RDP open. – Peter Schuetze Oct 21 '13 at 13:55
  • 1
    So there's no way to do it without setting up with a physical machine? I am sure it will work with a physical machine since it is working fine if I have a RDP connection open. But that's expensive to have. It can't be run virtually like a virtual linux machine can? – Kelvin Oct 21 '13 at 17:53
  • It can, as long as you have an rdp open to the virtual machine. UI tests need the UI components. – Peter Schuetze Oct 21 '13 at 18:00
  • because we have another testing environment running on linux, and with the use of xvnc, it is able to work without having any remote connection to it. I was hoping windows can work similar to that. – Kelvin Oct 21 '13 at 20:01
  • xvnc does for linux what rdp (a VNC server might also be enough) on Windows. Different name for the same animal. Both tell the OS "there is someone who wnats to see an UI". – Peter Schuetze Oct 21 '13 at 20:15
  • I set this up and it is basically working, although it looks like the UI tests sometimes hang and if I open a RDP connection they continue. Was that only coincidence or has somebody similar problems? – jan Jul 17 '14 at 14:04
  • 3
    I was able to setup this in a win7 VM following the steps mentioned by Peter. Additionally to make sure it worked without a RDC connection I added a shortcut to a batch file with this contents: for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do ( %windir%\System32\tscon.exe %%s /dest:console` ) Make sure you use this shortcut to disconnect instead of closing the Remote Desktop window. – JavierJ Sep 28 '15 at 15:09
  • This answer works great for me (I have a physical machine). I have not tested this without a monitor yet, however if I run into problems I know that they can be solved with a dummy VGA connector (aka 3 resistors). google for 'VGA dummy plug' – benathon Jul 21 '16 at 22:22
8

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

(slave.jar can be downloaded from http://{Your Jenkins Server}:8080/jnlpJars/slave.jar)

EDIT : If you're getting black screenshots (when using Selenium 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
Community
  • 1
  • 1
Noam Manos
  • 15,216
  • 3
  • 86
  • 85
3

The following thing did the trick for me:

In Jenkins execute windows shell command:

  • cmdkey /generic:TERMSRV/<servername> /user:<username> /pass:<password>
  • mstsc /v:<servername> /w:<width> /h:<height>
  • cd <path to your pom.xml>
  • <maven command>(e.g. mvn test -Dfiles_to_run=groupLaunch.xml
  • cmdkey /delete:TERMSRV/<servername>

It creates real mstsc session (Win-to-Win) with specified width and height in your virtual mstsc session (Jenkins-to-Win) powered by Jenkins.

dred17
  • 139
  • 2
  • 17
0

I tried the solutions provided here but nothing worked for me. At the end, I came up with a workaround.

I opened an RDP connection to the VM in a different VM (VM2). I left the first connection open inside VM2 and disconnected from it.

It worked but that implies having two virtual machines available.

ddarellis
  • 3,912
  • 3
  • 25
  • 53
0

You still need to use RDP but in my case, we can use loopback of the RDP in same VM.

The procedure:

  1. In a VM, create two different accounts, and create Jenkins slave for both of account.

Now you'll have two Jenkins slave for two accounts in one VM

slave 1 - account 1

slave 2 - account 2

  1. Enable multiple RDP follow guide https://www.serverwatch.com/server-tutorials/how-to-enable-concurrent-remote-desktop-sessions-in-windows.html

  2. In slave 2(with account 2), run rdp command to connect to slave 1(with account 1), like following Start /b "" "C:\RDP\rdp.exe" /v:127.0.0.2 /domain:\ /u:admin /p:xxxx /fullscreen /w:1920 /h:1200

127.0.0.2 is very important, it's a loopback connection for RDP

Put above command into Jenkins job with the name such as "OpenRDP_ToVMXXX, and then you can run any test on slave 1 with GUI enabled, enjoy.

August
  • 13
  • 3
0

As the solutions above seemed a bit overkill, I used this approach:

  1. Disable Jenkins service
  2. Start Jenkins from command line using java -jar C:\Program Files (x86)\Jenkins\jenkins.war

For some reason I had to install all plugins and everything when starting it this way, so I recommend creating a backup, there is a plugin for that. Good luck. :)

Daniel
  • 980
  • 9
  • 20