Custom collapsible sections - section markers still visible in rendered job log

Custom section markers still visible in rendered job log

Hi there, I have a question regarding custom collapsible section in job logs. I’ve followed the instructions from Custom collapsible sections. The section is indeed collapsible, however the section markers are still visible. As I understand it, they should be hidden, taken care by the escape sequences in the echo command.

I’m using Gitlab.com ( GitLab Enterprise Edition 14.4.0-pre) with shared-runners.

# test collapsible gitlab ci sections
stages:
  - test-collapsible-section

default:
  image: node:12.13.0

test-collapsable-section:
  stage: test-collapsible-section
  script:
    - echo -e "\e[0Ksection_start:`date +%s`:my_first_section\r\e[0K\e[36;1mHeader of the 1st collapsible section\e[0m"
    - echo 'this line should be hidden when collapsed'
    - echo -e "\e[0Ksection_end:`date +%s`:my_first_section\r\e[0K"

And here is the output:

Raw log:

e[0KRunning with gitlab-runner 14.4.0-rc1 (bc99a056)e[0;m
e[0K  on docker-auto-scale 72989761e[0;m
section_start:1634553967:prepare_executor
e[0Ke[0Ke[36;1mPreparing the "docker+machine" executore[0;me[0;m
e[0KUsing Docker executor with image node:12.13.0 ...e[0;m
e[0KPulling docker image node:12.13.0 ...e[0;m
e[0KUsing docker image sha256:11e92fc50c4a4f575757aa1d3d1d89a732b426269a9beb29d97b31b68950bd6f for node:12.13.0 with digest node@sha256:fc6c1371e3a0883f17e34492bcaffb4d8ad986ebb4a5eeafa8817bd425446566 ...e[0;m
section_end:1634554005:prepare_executor
e[0Ksection_start:1634554005:prepare_script
e[0Ke[0Ke[36;1mPreparing environmente[0;me[0;m
Running on runner-72989761-project-30539611-concurrent-0 via runner-72989761-srm-1634553924-9b9c5e95...
section_end:1634554008:prepare_script
e[0Ksection_start:1634554008:get_sources
e[0Ke[0Ke[36;1mGetting source from Git repositorye[0;me[0;m
e[32;1m$ eval "$CI_PRE_CLONE_SCRIPT"e[0;m
e[32;1mFetching changes with git depth set to 50...e[0;m
Initialized empty Git repository in /builds/martin.petro111/gitlab-collapsable-sections/.git/
e[32;1mCreated fresh repository.e[0;m
e[32;1mChecking out db5b27f3 as main...e[0;m

e[32;1mSkipping Git submodules setupe[0;m
section_end:1634554009:get_sources
e[0Ksection_start:1634554009:step_script
e[0Ke[0Ke[36;1mExecuting "step_script" stage of the job scripte[0;me[0;m
e[0KUsing docker image sha256:11e92fc50c4a4f575757aa1d3d1d89a732b426269a9beb29d97b31b68950bd6f for node:12.13.0 with digest node@sha256:fc6c1371e3a0883f17e34492bcaffb4d8ad986ebb4a5eeafa8817bd425446566 ...e[0;m
e[32;1m$ echo -e "\e[0Ksection_start:`date +%s`:my_first_section\r\e[0KHeader of the 1st collapsible section"e[0;m
e[0Ksection_start:1634554011:my_first_section
e[0KHeader of the 1st collapsible section
e[32;1m$ echo 'this line should be hidden when collapsed'e[0;m
this line should be hidden when collapsed
e[32;1m$ echo -e "\e[0Ksection_end:`date +%s`:my_first_section\r\e[0K"e[0;m
e[0Ksection_end:1634554011:my_first_section
e[0K
section_end:1634554010:step_script
e[0Ksection_start:1634554010:cleanup_file_variables
e[0Ke[0Ke[36;1mCleaning up project directory and file based variablese[0;me[0;m
section_end:1634554011:cleanup_file_variables
e[0Ke[32;1mJob succeedede[0;m

Any help would be much appreciated.

Thanks

The one major difference I notice between the example in the documentation you linked to and your own job is that you’re trying to color your hidden section headers. (Which doesn’t really make sense, they’re supposed to be invisible in the colored log.) And I notice, in fact, those color escapes don’t appear in the raw job log.

It may be that the color change is overriding the hidden-line escape and making the header visible. Try it without decoration:

test-collapsable-section:
  stage: test-collapsible-section
  script:
    - echo -e "\e[0Ksection_start:`date +%s`:my_first_section\r\e[0KHeader of the 1st collapsible section"
    - echo 'this line should be hidden when collapsed'
    - echo -e "\e[0Ksection_end:`date +%s`:my_first_section\r\e[0K"

That matches the example in the documentation, so it’s logical to assume it should work the same.

Actually, even then… I’m not sure it’s not working exactly the way it’s supposed to. The example doc never actually shows the colored log output for the sample code, and “Header of the 1st collapsible section” seems like it implies, to me, that it would be visible. If you want the collapsible section to have no header, just don’t add any text after the marker. But if you give it a header, I would expect that the header would be exactly the thing that is visible when it’s collapsed.

Hi,

thanks for your reply. I was trying to color the header “Header of the 1st collapsible section”, because I think that’s what should be visible in the rendered log.

I’ve tried it without the color as well, but the result is the same.

# test collapsible gitlab ci sections
stages:
  - test-collapsible-section

default:
  image: node:12.13.0

test-collapsable-section:
  stage: test-collapsible-section
  script:
    - echo -e "\e[0Ksection_start:`date +%s`:my_first_section\r\e[0KHeader of the 1st collapsible section"
    - echo 'this line should be hidden when collapsed'
    - echo -e "\e[0Ksection_end:`date +%s`:my_first_section\r\e[0K"

Output:

Raw log:

e[0KRunning with gitlab-runner 14.4.0-rc1 (bc99a056)e[0;m
e[0K  on docker-auto-scale fa6cab46e[0;m
section_start:1634627375:prepare_executor
e[0Ke[0Ke[36;1mPreparing the "docker+machine" executore[0;me[0;m
e[0KUsing Docker executor with image node:12.13.0 ...e[0;m
e[0KPulling docker image node:12.13.0 ...e[0;m
e[0KUsing docker image sha256:11e92fc50c4a4f575757aa1d3d1d89a732b426269a9beb29d97b31b68950bd6f for node:12.13.0 with digest node@sha256:fc6c1371e3a0883f17e34492bcaffb4d8ad986ebb4a5eeafa8817bd425446566 ...e[0;m
section_end:1634627409:prepare_executor
e[0Ksection_start:1634627409:prepare_script
e[0Ke[0Ke[36;1mPreparing environmente[0;me[0;m
Running on runner-fa6cab46-project-30539611-concurrent-0 via runner-fa6cab46-srm-1634627276-ed3e8ed3...
section_end:1634627411:prepare_script
e[0Ksection_start:1634627411:get_sources
e[0Ke[0Ke[36;1mGetting source from Git repositorye[0;me[0;m
e[32;1m$ eval "$CI_PRE_CLONE_SCRIPT"e[0;m
e[32;1mFetching changes with git depth set to 50...e[0;m
Initialized empty Git repository in /builds//gitlab-collapsable-sections/.git/
e[32;1mCreated fresh repository.e[0;m
e[32;1mChecking out bbdb86be as main...e[0;m

e[32;1mSkipping Git submodules setupe[0;m
section_end:1634627412:get_sources
e[0Ksection_start:1634627412:step_script
e[0Ke[0Ke[36;1mExecuting "step_script" stage of the job scripte[0;me[0;m
e[0KUsing docker image sha256:11e92fc50c4a4f575757aa1d3d1d89a732b426269a9beb29d97b31b68950bd6f for node:12.13.0 with digest node@sha256:fc6c1371e3a0883f17e34492bcaffb4d8ad986ebb4a5eeafa8817bd425446566 ...e[0;m
e[32;1m$ echo -e "\e[0Ksection_start:`date +%s`:my_first_section\r\e[0KHeader of the 1st collapsible section"e[0;m
e[0Ksection_start:1634627413:my_first_section
e[0KHeader of the 1st collapsible section
e[32;1m$ echo 'this line should be hidden when collapsed'e[0;m
this line should be hidden when collapsed
e[32;1m$ echo -e "\e[0Ksection_end:`date +%s`:my_first_section\r\e[0K"e[0;m
e[0Ksection_end:1634627413:my_first_section
e[0K
section_end:1634627413:step_script
e[0Ksection_start:1634627413:cleanup_file_variables
e[0Ke[0Ke[36;1mCleaning up project directory and file based variablese[0;me[0;m
section_end:1634627414:cleanup_file_variables
e[0Ke[32;1mJob succeedede[0;m

Hello.

I details my tests in an issue where you can see the effect of \r\e[0K on the rendered log.

The actual problem is the echo line which should be hidden, I didn’t find any way to hide the display of script lines.

Regards.