Search code examples
javajenkinsjenkins-pipelineexecutable-jar

Run a jar file from a specified folder in jenkins pipeline


I have an application developed using java , and the runnable jar is created which is working from the command line. To run the jar file , normally I used to open a command line from the folder where jar is placed. And to run the jar file, if the jar is placed in D:/ drive, then D:/>java -jar abc.jar will run the application

Now I want to run this jar file in a system , through jenkins pipeline.

The pipeline job is created. I want to know

  1. How pipeline can access a specified folder?
  2. Open a cmd.exe from that specified folder
  3. Run the jar file from that location

Expected result

From Jenkins pipeline job -> Access and run a jar file kept in a specified folder

Or is there any other way of doing it to get the expected result?

Thank you for the support!!


Solution

  • You can use dir to access the folder with the path where your jar file is available.

    // dir("<Your path where scripts are present>")
    dir ("D://"){
     // Execute your java file
     bat "java -jar abc.jar"
     }