I am trying to write gradle task which do the following:
- Executes script to obtain some data (let's say there is curl inside)
- Sets a environment variable with this data.
I would like to set this env variable so other gradle tasks can use it for further processing.
My code looks like this:
task myTask(type: Exec) {
executable "sh"
args "-c", "export", "myVar=\$(sh ./script.sh)"
doLast {
println System.getenv("myVar")
}
}
However when executing I see in the console all my env variables being printed (export KEY=VALUE) and System.getenv("myVar") prints null.
What am I doing wrong? Maybe there is better way to achieve my goal?