Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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().

question from:https://stackoverflow.com/questions/65902824/using-sh-vs-execute-in-a-jenkins-groovy-shared-library-design-switches-be

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...