Execute Shell or Jar from Gradle

1_-3BcPdB6bl6Q6TcFWimcTADuring one my project i had to execute shell script from gradle. It was bit of challenge to find out for me how can i achieve it. I am adding that snippet here so next time i remember as well someone else who wants to do the same.  This gradle script is created using gradle 4.1.X, here is the sample task which is used to integrate gradle script  to run shell script during one of jenkins build.


task (‘runShell’){
doLast {
       //description (‘Run shell script .’)
        println”Start executing the script from $location”
      exec {
                commandLine “sh”,”$location/run.sh”
           println”Finish executing the script from $location”
  Above code need to be added into your gradle script and just update the location of your shell script , and modify your script as you like. Configure this task to run from your jenkins build and here you go.
In addition to shell script you can run your jar file, Here is the snippet which i used for my project.
javaexec {
    main = “-jar”;
     args = [
Above code will pick up your jar and execute from your gradle task.

Published by sbcons

Sbcons has expertise in different areas of SDLC, provide solution, services and consultancy to all type of industry.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: