Cannot get collapsible sections to work from a Powershell script

Runner version is 14.5.0
Gitlab version is 14.3.3-ee
Runner is on Windows 10, with PowerShell version 5.1.19041.1237
The runner is using the shell runner, so is not running through docker or anything

The only really relevant bit of my .gitlab-ci.yml would be that my script block is just:

script:
  - ci/build.ps1

The script contents in question (it’s quite a big script, but I’ve tried these snippets in a vacuum with the same results):

$ESC = [char]27
$RET = [char]13

function Get-UnixTimeStamp {
    return [DateTimeOffset]::UtcNow.ToUnixTimeSeconds()
}

function Print-SectionStart($key, $title) {
    Write-Output "$($ESC)[0Ksection_start:$(Get-UnixTimeStamp):$($key)[collapsed=true]$($RET)$($ESC)[0K$($title)"
}

function Print-SectionEnd($key) {
    Write-Output "$($ESC)[0Ksection_end:$(Get-UnixTimeStamp):$($key)$($RET)$($ESC)[0K"
}

Print-SectionStart("test_section", "Test Section")
echo "Hello World."
Print-SectionEnd("test_section")

No matter how hard I try, I cannot get GitLab to create collapsible sections for me. It removes them from the parsed log as you’d expect, but doesn’t actually turn them into sections (or show the section title). I can however still see them in the raw log but the output seems to end up slightly different?

e[0Ksection_start:1638010926:test_section Test Section[collapsed=true]
e[0K

Something I did notice (not sure if it’s relevant) is that the sections that are parsed that are auto-generated by the runner seem to not follow the same format:

section_end:1638010824:get_sources
e[0Ksection_start:1638010824:step_script

I can confirm that it definitely prints both the start and end of each section.

I’ve already tried a couple of variations of the start/end blocks including without a human-readable title, with/without the collapsed parameter, and have checked both the docs for collapsible sections and also this thread

1 Like