2

How to execute a JAR file from Jenkins?

I have a JAR output from a gradle build section, i want to execute this JAR file after it created. I am using a Jenkins platform setup in windows server. I don't have any separate node for execution, master itself acts as both server and node.

Tried several ways but not working as expected. The JAR file is working if i run in a normal windows batch command window but the same command is not working if i executed it from a Jenkins windows batch command build section.

Any help would be appreciated.

Saikat
  • 14,222
  • 20
  • 104
  • 125
Kalesh Es
  • 53
  • 1
  • 5
  • In which way does it not work? No effect? Wrong effect? Crash? Hang? – Yunnosch Sep 04 '18 at 06:16
  • can you paste the batch command you use to run in Jenkins – rohit thomas Sep 04 '18 at 07:26
  • @rohit : start java -jar -Dspring.profiles.active=XYZ %JAR_PATH%\test.jar – Kalesh Es Sep 04 '18 at 08:31
  • @Yunnosch: There is no effect..the jar is not executing (jar file is called inside the batch script) – Kalesh Es Sep 04 '18 at 08:33
  • First: Remove the trailing "start", so the JVM will be called in the same shell, and you will get the output if any errors had happened. – Little Santi Sep 04 '18 at 23:01
  • Anyway, I'd bet the order of options in your call is incorrect: It should be `java -D... -jar jarfile` – Little Santi Sep 04 '18 at 23:02
  • I have given the following commands in the post build script and it started working. The first command will kill the running instance of the JAR an start the new instance as well....Thanks all for the support for /f "tokens=1" %%i in ('jps -m ^| find "%BIN_JAR_NAME%"') do ( taskkill /F /PID %%i ) start java -jar -Dspring.profiles.active=**** %OUTPUT_PATH%\%BIN_JAR_NAME% – Kalesh Es Sep 11 '18 at 05:01
  • Please [edit] your question to add useful information, instead of hiding it in comments. – Yunnosch Sep 11 '18 at 05:24
  • Please take the [tour]. – Yunnosch Sep 11 '18 at 05:25
  • Thank you all (rohit, Yunnosch and Little Santi) for the great support... – Kalesh Es Sep 12 '18 at 05:00

1 Answers1

0

The following commands in the post build script started working. The first command will kill the running instance of the JAR and start the new instance as well.

 for /f "tokens=1" %%i in ('jps -m ^| find "%BIN_JAR_NAME%"') do ( taskkill /F /PID %%i ) start java -jar -Dspring.profiles.active=**** %OUTPUT_PATH%\%BIN_JAR_NAME%
Saikat
  • 14,222
  • 20
  • 104
  • 125