How to run command 'export ENV_VAR=Value' without error Cannot cast object 'export' with class 'java.lang.String' to class 'java.lang.Iterab

i am trying to run command ‘export ENV_VAR=Valeu’ with the following task:

task importHost(type:Exec){

commandLine = ‘export’

args = ‘CONTROLLER_HOST=host’

}

This return the following error:

Cannot cast object ‘export’ with class ‘java.lang.String’ to class 'java.lang.Iterable

Would mind, please, point me the right direction how to run ‘export’ command via Gradle. Thank you

Usually, ‘export’ is a built-in shell command, and it doesn’t make sense to run it on its own. The error you get is for a different reason, namely that ‘args’ is a list of arguments. Either leave off the ‘=’, or use ‘args = [ … ]’.

Thank you Peter. However, your solutions doesn’t work. I am still getting the same error with (args ‘CONTROLLER_HOST=host’) or (args = [‘CONTROLLER_HOST=host’]). your help is much appreciated.

So, i end up doing as following: task importHost(type:Exec) {

executable “bash”

args “-c”, “export”, “CONTROLLER_HOST=host”

}

Peter, when you said ‘export is a built-in shell command, and it doesn’t make sense to run it on its own’, did you mean that the ‘export’ is run as a separate child process, so exporting any variables wouldn’t be available in the parent where gradle is executing so its worthless, correct? If so, how do we import Env variables with gradle, so they are available in the parent process? Thank YOu