0
votes

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.

2
start "window_name" cmd /c "java -jar myjarfile.jar" - r3ap3r
@r3ap3r thanks. but the result is same :( - Charls
Why do you want a console to popup? A popup would not work for the Jenkins HTTP interface anyway. - David Ruhmann

2 Answers

1
votes

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

0
votes

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.