Jenkins执行shell行为不同

rxztt3cl  于 2023-01-25  发布在  Jenkins
关注(0)|答案(1)|浏览(298)

bounty将在5天后过期。回答此问题可获得+300的声誉奖励。Abhishek正在寻找来自声誉良好来源的答案

我正在创建一个Jenkins项目,该项目在生成时执行shell。在执行shell中,我正在运行一个python脚本,如“python3pythonScriptFile.py“”${arg 1}”“${arg 2}”“${arg 3}”
python文件内部调用shell脚本。
python -〉shell 1-〉shell 2-〉返回python文件以继续执行。
当我在终端中使用参数执行python文件时,执行是一个接一个同步的。
但是当我在Jenkins中运行相同的命令时,首先执行shell,然后执行Python文件。

`print("SCRIPT Started")
 process = os.system("""sh script.sh -t {arg1} -e {arg2}""")
 process.wait()
 if process.returncode != 0:
     sys.exit()
     print("Error executing build script")

 print("SCRIPT COMPLETED")`

输出:

Script executed (which is a echo inside shell)
SCRIPT Started
SCRIPT COMPLETED`

预期输出:

SCRIPT Started
Script executed (which is a echo inside shell)
SCRIPT COMPLETED`
wydwbb8l

wydwbb8l1#

[为什么会这样?]
标准输出流的缓冲取决于环境和程序设置。
在Jenking中,python程序的输出流是全缓冲的,而连接到终端的交互程序是行缓冲的。
【怎么修?】
Disable output buffering

相关问题