2
votes

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.

1
In which way does it not work? No effect? Wrong effect? Crash? Hang?Yunnosch
can you paste the batch command you use to run in Jenkinsrohit thomas
@rohit : start java -jar -Dspring.profiles.active=XYZ %JAR_PATH%\test.jarKalesh Es
@Yunnosch: There is no effect..the jar is not executing (jar file is called inside the batch script)Kalesh Es
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

1 Answers

0
votes

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%