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

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

using sh() vs. execute() in a Jenkins Groovy shared library design - switches between hosts?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...