Jenkins 执行 shell 的行为不同

Abh*_*hek 1 python shell jenkins

我正在创建一个 Jenkins 项目,它在构建时执行 shell。在执行 shell 中,我正在运行一个 python 脚本,例如 `python3 pythonScriptFile.py "${arg1}" "${arg2}" "${arg3}"

python文件内部调用shell脚本。

python -> shell1 -> shell2 -> 返回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")`
Run Code Online (Sandbox Code Playgroud)

输出:

Script executed (which is a echo inside shell)
SCRIPT Started
SCRIPT COMPLETED`
Run Code Online (Sandbox Code Playgroud)

预期输出:

SCRIPT Started
Script executed (which is a echo inside shell)
SCRIPT COMPLETED`
Run Code Online (Sandbox Code Playgroud)

Kam*_*Cuk 5

[为什么会出现这种情况?]

标准输出流的缓冲取决于环境和程序设置。

在 Jenking 中,python 程序的输出流是完全缓冲的,而连接到终端的交互式程序是行缓冲的。

[如何解决?]

禁用输出缓冲