Search code examples
shelljenkinsgroovypipeline

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


I have a job in Jenkins with a shell script that I want to save its output to a file and in the same time print to console, is that possible?

The shell script is doing docker login and docker run(this will pull the image too) and I want the output to be saved into a file and also printed in real time (printing the file content later on won't have the same effect)

Can someone assist?


Solution

  • Use tee.

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

    eg:

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