0
votes

We use Jenkins and PowerShell to do a lot of automation within our organization. It is great for deployments, scheduled tasks, restarting services, recycling IIS app pools, etc. Now I'd like to use to restart our console applications that run on Windows servers.

The exe console applications will launch a GUI that must remain running in the users console session on the server. Services are much easier to control and this methodology requires us to always have an active session to run which we monitor via RDP, but it is too late to argue with the developers who architected the system.

Jenkins is running as a service and when I start an exe, i.e. with

& 'C:\gui.exe'

it starts the process in task manager, but does not launch the GUI in the session so I can see it. Jenkins will report an error:

Process leaked file descriptors. See http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build for more information

but the page does not explain how to target a particular console session and launch a visible GUI. Am I missing something? Help appreciated...

2

2 Answers

0
votes

Research brought me to this workaround, but it is not an answer to my question:

https://wiki.jenkins-ci.org/display/JENKINS/Tomcat

I provide it here since it will help me get moving and will hopefully help others with the same problem, but doesn't resolve the issue fully. What this says is to NOT allow the Jenkins agent to be Windows Service. When we leave the browser pop-up jnlp connection open, it works for launching GUI's in the session, but if the pop-up is closed, the server rebooted, etc we lose our connection and manual intervention is needed to connect the slave again. The resolution to that part is to put the launching of the jnlp agent into Windows Scheduler to run at logon. Or be paranoid and write a script to check if it is running and launch it if not, then have that run on the scheduler every x minutes.

As I said, this works, but it requires me to go back through the environment and change the way the slave agents are set up to a less robust model. Not ideal, but it works.

Hopefully someone else may have a better solution (although the Jenkins/Hudson wiki page says it isn't really possible). I'm not asking for a Jenkins solution, I'm looking more for a PowerShell solution that would allow me to target a particular console session, but taking into account the unique way PowerShell is run through Jenkins (non-interactive shell).

0
votes

I have had both issues you report: not launching the GUI, and the file descriptor leak messages. Here's how I solved them.

Issue 1 solution. Dont launch Jenkins as a service. But default, Jenkins installs on Windows as a service using System account. But services do not have access to the desktop, esp. the System account, which negates running GUI apps. Even checking that box "Allow service to interact with the desktop" does not do enough or changing the logon account for the service. Launch Jenkins from command line.

Issue 2 solution. I did two things. First added

-Dhudson.util.ProcessTree.disable=true

argument to command line launch. Second, add environment variable:

SET BUILD_ID=dontKillMe

to the job which I added to the Jenkins job itself. So although I have a Powershell section to the Jenkins job, I also have an "Execute Windows batch command section" with the SET command which I placed PRIOR to the Powershell section.

BTW here is complete command line to launch which I placed in a batch file:

CD "C:\Program Files (x86)\Jenkins"
java -Dhudson.util.ProcessTree.disable=true  -jar jenkins.war --httpListenAddress=127.0.0.1 --httpPort=8081 

As it happens I run somthing else on 8080 so I changed port.

Hope this helps!