Search code examples
javajenkinsjenkins-pluginsjenkins-pipelinejenkins-cli

How to run a JAR file using Jenkins


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.


Solution

  • 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%