"sudo".execute() and retain env vars

I have a requirement where I need to sudo into an oracle user, retain the environment variables from the gradle wrapper, execute the task and return.

println “$System.env.ORACLE_INSTANCE/bin/frmf2xml.sh $file OVERWRITE=YES”.execute().text

the above works perfectly if run as the oracle user. However, the following does not:

println “sudo -u oracle -E $System.env.ORACLE_INSTANCE/bin/frmf2xml.sh $file OVERWRITE=YES”.execute().text

How does it not work? Do you get an error message? Does it do the wrong thing?

Unfortunately, the error messages are terrible, but we have proven its an environment issue by creating a wrapper around the frmf2xml.sh that also sets the environment. This works:

println “sudo -u oracle /home/frm2xmlWrapper.sh”.execute().text

Interestingly this was completely unrelated to environment variables, it was indeed doing as expected. It was my permissions on files during the sudo that was causing the problem.

This can be closed.

Thanks for letting me know. Cheers.