Skip to content

Instantly share code, notes, and snippets.

@diegopacheco
Created September 11, 2015 23:04
Show Gist options
  • Save diegopacheco/e32c6fc2f0c4febb872a to your computer and use it in GitHub Desktop.
Save diegopacheco/e32c6fc2f0c4febb872a to your computer and use it in GitHub Desktop.
How to Run BASH script from Gradle Task?
task hello(type: Exec) {
executable "sh"
args "-c", "echo 'hello from your shell'"
}
@Drjacky
Copy link

Drjacky commented Feb 14, 2020

How to pass path of sh file?
None of these worked for me:

task runInstrumentationTestsOnTestLab(type: Exec) {
    //commandLine 'sh', './instrumentationTestLab.sh'
    /*doLast {
        exec {
            executable ".././instrumentationTestLab.sh"
        }
    }*/
    //Runtime.getRuntime().exec("./instrumentationTestLab.sh")
    /*preBuild.doFirst {
        println("Executing myScript")
        def proc = "./instrumentationTestLab.sh".execute()
        proc.waitForProcessOutput(System.out, System.err)
    }*/
    /*preBuild.doFirst {
        println("Executing runInstrumentationTestsOnTestLab")
        def proc = Runtime.getRuntime().exec("./instrumentationTestLab.sh")
        proc.waitForProcessOutput(System.out, System.err)
    }*/
    //commandLine 'sh ./instrumentationTestLab.sh'
    executable "sh"
    args "-c", "./instrumentationTestLab.sh"
}

@pandelisgreen13
Copy link

thanks a lot for your help, you saved my day about the shell scripts

@tsouza
Copy link

tsouza commented Apr 7, 2023

This doesn't seems to work with latest gradle version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment