Improve the collapsible element logic
What does this MR do?
Improve the collapsible logic. The changes made in this MR works well with the changes made implemented in this GitLab MR: gitlab!136186 (merged)
The improvements added are the following:
- Single line commands don't show in collapsible element
- For multi-line command, only the multi-line command is collapsible
It requires the FF_SCRIPT_SECTIONS
to be enabled
This MR also changes the the behaviour brought by the FF_SCRIPT_SECTIONS
Previous behaviour
When FF_SCRIPT_SECTIONS
is enabled, each command becomes a script section meaning:
- The command and its outputs are part of the same collapsible element
- The duration of the command is displayed.
However this was only functional for bash
shell and in the event of nested collapsible elements, the parent element was broken and could not be collapsed.
New behaviour
When FF_SCRIPT_SECTIONS
is enabled, multi line command are displayed and are collapsed by default in the job log. The duration is no longer displayed. Users, however, still have the ability to created custom collapsible section
.
To do so, they should add the following command at the beginning and the end of the desired section:
Bash
- To start a section:
echo -e "\033[0Ksection_start:`date +%s`:SECTION_UNIQUE_IDENTIFIER\r\033[0KNAME_OF_THE_SECTION"
- To end a section:
echo -e "\033[0Ksection_end:`date +%s`:SECTION_UNIQUE_IDENTIFIER\r\033[0K"
PowerShell
- To start a section:
Write-Output "section_start:$([MATH]::Round((Get-Date -UFormat %s))):SECTION_UNIQUE_IDENTIFIER$([char]0x0D)$([char]0x1B)[0KNAME_OF_THE_SECTION`
- To end a section:
echo -e "\033[0Ksection_end:$([MATH]::Round((Get-Date -UFormat %s))):SECTION_UNIQUE_IDENTIFIER$([char]0x0D)$([char]0x1B)[0K"
Why was this MR needed?
Improve the way collapsible section were handled.
What's the best way to test this MR?
gitlab-ci
variables:
FF_PRINT_POD_EVENTS: "true"
FF_USE_POWERSHELL_PATH_RESOLVER: "true"
FF_SCRIPT_SECTIONS: "false"
collapsible_job_multiple:
stage: build
script:
- |
echo "{
'test': 'data',
'test2': 'data2',
}"
- |
echo "{
'test': 'data',
'test2': 'data2',
}"
- echo -e "\033[0Ksection_start:`date +%s`:my_first_section\r\033[0KHeader of the 1st collapsible section"
- echo 'this line should be hidden when collapsed'
- |
echo "{
'test': 'data',
'test2': 'data2',
}"
- echo -e "\033[0Ksection_start:`date +%s`:second_section\r\033[0KHeader of the 2nd collapsible section"
- echo 'this line should be hidden when collapsed'
- echo -e "\033[0Ksection_end:`date +%s`:second_section\r\033[0K"
- echo -e "\033[0Ksection_end:`date +%s`:my_first_section\r\033[0K"
Use the suitable binary from https://gitlab-runner-downloads.s3.amazonaws.com/collapsible-multi-command-and-section-improvement/index.html
Any config.toml
with any executor
should work. My tests were made with executorkubernetes
Screen_Recording_2023-11-28_at_2.26.56_PM
What are the relevant issue numbers?
close #3392 (closed) close gitlab#409350 (closed)