Skip to content
Latchkey

tee Command Reference for CI Scripts

tee copies stdin to one or more files and also passes it through to stdout.

tee lets a CI step both stream output to the console and capture it to a log file for later upload. The catch is how it interacts with pipefail and exit status.

Common flags/usage

  • tee FILE: write stdin to FILE and to stdout
  • -a / --append: append instead of truncating
  • tee FILE1 FILE2: write to several files at once
  • -i: ignore interrupt signals
  • sudo tee: the idiom for writing to a root-owned file via a pipe

Example

shell
./build.sh 2>&1 | tee "build-${GITHUB_RUN_ID}.log"
echo "deb https://repo.example.com stable main" \
  | sudo tee /etc/apt/sources.list.d/example.list

In CI

cmd | tee log.txt makes the pipeline exit status that of tee (usually 0), so a failing cmd is masked unless set -o pipefail is on; with pipefail the real failure propagates. sudo tee is the standard way to write a root-owned file from a pipe, since redirection runs as the unprivileged shell.

Key takeaways

  • Without pipefail, cmd | tee hides a failing cmd behind tee\u2019s exit 0.
  • sudo tee writes root-owned files where shell redirection cannot.
  • Use -a to append to a running log instead of truncating it.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →