Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get parts of my GitLab CI Job Log to fold when viewed on the GUI?

Tags:

gitlab-ci

I have several GitLab CI Jobs which take a while to run. I already use the before_script and after_script features to break some of the work into sections. I would like to add further collapsible log sections within the Job output if that is possible.

Example of Collapsible Job Output as provided by GitLab

The job sections I can view presently on the GitLab web-interface include timings for each of the collapsible sections shown (see above image). If I could get more granular timings for each of the new sections created that would be a nice bonus but it is not essential.

I am currently using GitLab Community Edition 12.6.4


I tried looking through the GitLab CI/CD Pipeline Configuration Reference but I could not find and notes on defining your own sub-sections within the log output. I found an issue requesting a Collapsible Job Log which does include some suggesting workarounds for adding it but as that issue is closed I thought there was perhaps a more official way than messing with the DOM. I would prefer to go with an answer of "it is not supported" then make a rob for my own back by doing anything too strange with the output that might break in the future.

like image 849
TafT Avatar asked Oct 15 '22 07:10

TafT


2 Answers

Were you looking for something like this?

- echo -e "section_start:`date +%s`:my_first_section\r\e[0KHeader of the 1st collapsible section"
- echo 'this line should be hidden when collapsed'
- echo -e "section_end:`date +%s`:my_first_section\r\e[0K"

as seen here https://docs.gitlab.com/ee/ci/jobs/#custom-collapsible-sections

like image 167
agotfrid Avatar answered Oct 21 '22 09:10

agotfrid


Not only can you define addition collapsible log sections, but with GitLab 13.5 (October 2020), said sections can be collapsed by default.

Pre-collapse sections in the job logs

Job logs often contain very long sections that make it difficult to parse when you are scanning the logs to find a specific piece of information.

Now you can set job log sections to be collapsed by default. To make parsing much easier, simply add [collapsed=true] to your job scripts in your CI/CD configuration file as needed.

See Documentation and Issue.

The original link is broken (still works, but links to the wrong page). Instead, look at Pre-collapse sections

Add [collapsed=true] after the section name and before the \r. The section end marker remains unchanged:

  • Section start marker with [collapsed=true]: \e[0Ksection_start:UNIX_TIMESTAMP:SECTION_NAME[collapsed=true]\r\e[0K + TEXT_OF_SECTION_HEADER
  • Section end marker: \e[0Ksection_end:UNIX_TIMESTAMP:SECTION_NAME\r\e[0K
like image 31
VonC Avatar answered Oct 21 '22 08:10

VonC