When using a piece of test code running 'sh' vs 'execute' i noticed a great differences in environment variables. It quickly looked as if two totally different host were involved - even if lines of invocation are only some two lines away on the very same script level.
My test codes are about that (simplified/principle):
sh("set")
[ "sh", "-c", "set" ].execute()
A sample build resulted in these outputs:
sh: HOSTNAME='jenkins-master-build-node-820bj'
execute: HOSTNAME=jenkins-master-8-v95jg
Many other differences in environment variables were observed. Rationale: This is definitely not the same runtime environment and probably not even the same computer system. I am puzzled at the moment!
How could that be understood? How could that be controlled? Indeed I want the execute() call behave identical to sh().