Home > front end >  How to save command output from Gitlab CI in docker container's syslog
How to save command output from Gitlab CI in docker container's syslog

Time:08-19

I am using Gitlab runners installed in Docker with Docker executors and I would like to save some logs to my docker container. In bash I can do something like this to redirect output to syslog:

echo "hi" | logger

But I would like to do this straight from my Gitlab CI script. Let's say I want my job to look like this.

    image: python:latest
    
    stages:
      - my_stage

    my_job:
      stage: my_stage
      tags:
        - test
      script:
        - echo "Hi - only print"
        - echo "Hi - print and save to syslog" | logger -s

I need to save the second output to syslog in docker container but don't know how to do this. I guess my solution doesn't work because I am trying to save it in the container dynamically created by Gitlab Runner. Is there some other way to make it?

CodePudding user response:

You can mount a file (or other descriptor) into your jobs and write to that.

For example, in your runner config:

    volumes = ["/var/log/ci-job-logs/"]

And in your job:

- echo "hello logfile" >> "/var/log/ci-job-logs/${CI_JOB_ID}.log"

The files are stored on the host, but you could share the mount point /var/log/ci-job-logs/ (or whatever file/directory you want) with other containers, like a containerized logging daemon, syslog tool, pipe to a command, etc.

  • Related