'How do I get parts of my GitLab CI Job Log to fold when viewed on the GUI?
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.
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.
Solution 1:[1]
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
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dediqated |
Solution 2 | Socowi |