Skip to content

Support of multi-line command output in job terminal output view for bash shell when FF_SCRIPT_SECTIONS is enabled

Romuald Atchadé requested to merge multi-line-command-uncollapsed into main

Status update of 2023-10-16

In this iteration we have introduced support for multi-line command output in the job terminal view, specifically for the bash shell. To offer users who may not be interested in this feature the option to maintain the existing view, we have made this feature toggleable via the Feature Flag FF_SCRIPT_SECTIONS.

When the multi-line command display is enabled, the command and its results are contained within a collapsible element, but please note that this functionality is currently available only for bash shell. No equivalent implementation has been made for PowerShell/pwsh at this time.

It's worth mentioning that the implementation for PowerShell/pwsh is still a work in progress due to an issue with the ANSI_CLEAR character, which somehow gets transformed into a newline in the job log. This leads to the section delimiter being inadvertently omitted during the rendering of the job log, resulting in the displayed output shown below.

$ Write-Host -NoNewline "section_start:$([MATH]::Round((Get-Date -UFormat %s))):my_first_section[collapsed=true]`rHeader of the 1st collapsible section"
section_start:1696982346:my_first_section[collapsed=true]
Header of the 1st collapsible section$ echo 'this line should be hidden automatically after loading the job log!'
this line should be hidden automatically after loading the job log!
$ Write-Host -NoNewline "section_end:$([MATH]::Round((Get-Date -UFormat %s))):my_first_section`r"
section_end:1696982346:my_first_section
Cleaning up project directory and file based variables

Multiple attempts made to force the display of ANSI_CLEAR were unsuccessful:

* `r`e[0k
* `r$([char]0x1B)[0K
* $([char]0x1B)$([char]0x1B)[0K
* etc ...

Here is the work left to do:

  • Support for section for PowerShell/pwsh
  • Fix nested collapsible element
  • Integration/unit tests

Status update of 2022-12-02

The MR is currently half ready. The implementation made is functional for the bash script but it breaks the nested collapsable elements. And a fix doesn't look that straightforward.

Here is an example for bash. Child collapsible functional, parent one broken

When it comes to the pwsh it just doesn't fold at all. The tag sent to delimit sections are not recognized as such so the collapsing doesn't happen at all. I suspected at the beginning an encoding issue but it doesn't seem to be the case 😞

What does this MR do?

Add support for multi-line command output in job terminal output view

Why was this MR needed?

To allow developers to see the full command when this one is on multi lines

What's the best way to test this MR?

gitlab-ci.yml
variables:
  FF_SCRIPT_SECTIONS: "true"

job:
  script: 
    - |
      echo "{
        'test': 'data',
      }"
    - |
      echo "{
        'test2': 'data2',
      }"

Bash

config.toml
check_interval = 1
log_level = "debug"

[session_server]
  session_timeout = 1800

[[runners]]
  request_concurrency = 1
  url = "https://gitlab.com/"
  token = "__TOKEN__"
  executor = "kubernetes"
  shell = "bash"
  [runners.kubernetes]
    pull_policy="always"
    image = "alpine:latest"
    namespace_overwrite_allowed = ""
    privileged = true
    allow_privilege_escalation = true
    service_account_overwrite_allowed = ""
    pod_annotations_overwrite_allowed = ""
    terminationGracePeriodSeconds = 30
    [runners.kubernetes.affinity]
    [runners.kubernetes.volumes]
    [runners.kubernetes.dns_config]

The multi-line commands should be collapsible

PowerShell/pwsh

config.toml
check_interval = 1
log_level = "debug"

[session_server]
  session_timeout = 1800

[[runners]]
  request_concurrency = 1
  url = "https://gitlab.com/"
  token = "__TOKEN__"
  executor = "kubernetes"
  shell = "pwsh"
  [runners.kubernetes]
    pull_policy="always"
    image = "mcr.microsoft.com/powershell:7.1.1-alpine-3.12-20210125"
    namespace_overwrite_allowed = ""
    privileged = true
    allow_privilege_escalation = true
    service_account_overwrite_allowed = ""
    pod_annotations_overwrite_allowed = ""
    terminationGracePeriodSeconds = 30
    [runners.kubernetes.affinity]
    [runners.kubernetes.volumes]
    [runners.kubernetes.dns_config]

For PowerShell/pwsh the whole command is printed without sections.

What are the relevant issue numbers?

#3392 (closed)

Edited by Romuald Atchadé

Merge request reports