在 Jenkins 中,同时将 shell 脚本打印到控制台日志和文件

In Jenkins, Print shell script to both console log and to a file in the same time

我在 Jenkins 有一份工作,有一个 shell 脚本,我想将其输出保存到一个文件,同时打印到控制台,这可能吗?

shell 脚本正在执行 docker logindocker run(这也会拉取图像)我希望将输出保存到文件中并实时打印(稍后打印文件内容不会有同样的效果)

有人可以帮忙吗?

在 shell 脚本中将结果输出到控制台并存储在某个文件中,您可以:

echo '<whatever you want to output>' >> <filename>

使用tee.

<command> 2>&1 | tee output.log

例如:

./docker_exec.sh 2>&1 | tee output.log