0

I'm trying to run a jar file using a bat command with jenkins. and I want to popup the cmd and execute the jar file. but the problem is jenkins execute commands inside its console. Then i inserted "start" command and hoped it'll work coz it creates a separate cmd to run the jar. here is my bat code

start "window_name" java -jar myjarfile.jar     

but when i executing using it jenkins it doesn't create a separate cmd window but it executes the jar file anyhow. it shows this line,

 C:\Update>start "window_name" java -jar myjarfile.jar

any idea how to solve this? I want to pop up a black window when executing.

Charls
  • 235
  • 1
  • 4
  • 13

2 Answers2

1

The trick is figuring out in what session you want to start the cmd.exe. On a remote server (which is most often the case with Jenkins), it's not necessary straight forward. Your Remote Desktop Session is not in the same session as someone who is logged in physically at the console.

  • Bring up Windows Task Manager
  • Click the Users tab
  • Note down the ID of the session of the logged in user that you want
  • Download psexec from Windows Sysinternals
  • Edited from here downwards
  • Open elevated command prompt: type cmd into Start's quicksearch, right click cmd.exe, select Run as Administrator.
  • Type C:\path\to\psexec.exe -accepteula and press enter.
  • Type C:\path\to\psexec.exe -i 1 cmd and press enter. (If you see a command prompt appear, all is good, close it now)
  • In Job configuration, configure Execute Windows Batch command step Write the following: C:\path\to\psexec.exe -accepteula && C:\path\to\psexec.exe -i 1 cmd /c start C:\full\path\to\java.exe -jar myjarfile.jar

A more detailed explanation is provided in this answer Open Excel on Jenkins CI

Community
  • 1
  • 1
Slav
  • 27,057
  • 11
  • 80
  • 104
  • Thanks bro. But still no change. . . – Charls Mar 19 '14 at 05:06
  • Prob is jenkins executes everything in its own environment. It can't access the current one. It asks permission to show results (to show the windows that are created by jar. . .etc) – Charls Mar 19 '14 at 08:30
  • Try adding `-s` to use Local System privileged account. Also, [accept the EULA](http://stackoverflow.com/questions/5151034/psexec-gets-stuck-on-licence-prompt-when-running-non-interactively/5151078#5151078) – Slav Mar 19 '14 at 13:01
  • Or you can try a "service" method workaround http://blogs.msdn.com/b/adioltean/archive/2004/11/27/271063.aspx – Slav Mar 19 '14 at 13:04
  • I've seen another similar question and that got me to actually try doing it. After some trial and error, I've got a working solution (for another .exe). I've modified the answer. – Slav Mar 24 '14 at 16:34
0

Thanks Guys, May be your solutions too will do the trick. Finally what I did is i created a socket program and executed server myself. Then scheduled jenkins to execute the client.(Server in my environment & client in jenkin's environment) When client connects to the server it executes the bat file. Now everything works fine.

Charls
  • 235
  • 1
  • 4
  • 13
  • Please see my answer here http://stackoverflow.com/questions/22602951/open-excel-on-jenkins-ci/22610664#22610664. Note about using `cmd /k` for debugging, as you will probably run into pathing issues – Slav Mar 24 '14 at 16:35