During 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 = [“$rootDir/libs/executable-all-1.0.jar”,“$arg1”,“$arg2”,“$arg3”]}
Above code will pick up your jar and execute from your gradle task.