How do I collect the logs for all jobs in a gitlab pipeline?

18.2k views Asked by At

I have some gitlab CI pipelines that consist of dozens of jobs -- sometimes I need to find something that might appear in a job without knowing which one. I can manually select each job in the web interface and review the associated log, but doing that for each job is infeasible.

Is there some way (ideally as an unprivileged gitlab user) to retrieve/aggregate the output from all the jobs of a given pipeline?

In case it matters, I'm using version 12.5.X-ee.

2

There are 2 answers

0
Katrin Leinweber On

This implements the essentials of Rekovni's suggestion: download_ci_logs.rb. It has a hard-coded CI- prefix and .log extension for the downloaded traces, plus a header that I found personally useful.

Improvement suggestions are welcome as comments here or issues in that project.

0
Rekovni On

You could use the GitLab Jobs API to aggregate all the job traces, and write a script with something along the lines of:

  • Add a final stage to your pipeline (aggregate job logs)
  • List the current Pipeline ID jobs
  • Loop over the JOB_IDs (apart from the aggregate job logs job), and get their job logs
  • Dump to a file and you can review all the logs in one file

Note, that you will need to create a personal-access-token, and then use it in the CI job to access the API. There's not a great way with storing your access token apart from as a custom environment variable, and then accessing that variable in the .gitlab-ci.yml.

HTH