I want to create collapsible sections, as the help here describes, but from within a PowerShell script that is called as part of the run.
So not in the .gitlab-ci.yml itself but within a PowerShell script that might be called from the “script” block.
I have made many attempts in vain and this does not seem possible. If I output from the PowerShell script through “Write-Output” including adding escape characters this does not work.
I have been able to add collapsible blocks if I add them as described in the help into the .gitlab-ci.yml. I assume Gitlab only processes the immediate sections in the yml to see if the collapsible block syntax exists.
Does anyone know if this is the case? Or has anyone gotten my scenario to work in PowerShell?
This is an old topic, but it’s still the first search result when I search DuckDuckGo for information about this, so I thought I’d provide an answer…
First, new versions of PowerShell support using backticks to print escape codes; see about Special Characters - PowerShell | Microsoft Docs. Unfortunately, it seems like that isn’t available on the Windows shared runners currently provided by GitLab. You can, however, use command substitutions to insert appropriate bytes in your strings manually.
Second, the PowerShell Get-Date function includes fractional sections when printing UNIX times, but GitLab doesn’t like that; it only wants whole seconds. So, you have to truncate the timestamps you put in your sections. Anyway, here’s an example of what works for me inside a .ps1 file: