gitlab-rake colors output even if stdout is not connected to a tty
Summary
When running rake tasks such as backup creation, the output is colored even when running via cron or when piping the output into another process/redirecting to a file. This makes for very ugly log files, cron emails etc.
Steps to reproduce
Multiple ways:
- Add
gitlab-rake gitlab:backup:create
to crontab and setMAILTO
to deliverable address - Run
sudo gitlab-rake gitlab:backup:create | cat
- Run
sudo gitlab-rake gitlab:backup:create > log
and check contents oflog
Expected behavior
Colors should be automatically disabled if stdout is not a tty.
Relevant logs and/or screenshots
Snippet from cron mail:
[0;34;49mDumping database ... [0m
Dumping PostgreSQL database gitlabhq_production ... [0;32;49m[DONE][0m
[0;32;49mdone[0m
[0;34;49mDumping repositories ...[0m
Possible fixes
There seems to be an available fix described in https://gitlab.com/gitlab-org/gitlab-ci/issues/164. Apparently, the described approach has not made it into master.