Home > Back-end >  Azure Devops Powershell not showing file names for Get-ChildItem
Azure Devops Powershell not showing file names for Get-ChildItem

Time:04-04

I'm using the following task in an Azure DevOps pipeline on vmImage: ubuntu-latest:

- pwsh: Get-ChildItem *.* -Recurse -Path $(Pipeline.Workspace)
  displayName: 'Show folder contents for debugging'

I'm doing so to dir out a list of files downloaded in a previous download pipeline artifact step. I've also tried regular powershell instead of Powershell Core.

The folder names are showing up correctly, and entries for files are seemingly being shown, but there are no file names included at all. Here's a part of the output I do see:

/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '/home/vsts/work/_temp/1f22f03a-d1c6-4983-a08e-39ed349876be.ps1'

    Directory: /home/vsts/work/1

UnixMode   User             Group                 LastWriteTime           Size
--------   ----             -----                 -------------           ----
drwxr-xr-x vsts             docker             04/03/2022 16:22           4096
drwxr-xr-x vsts             docker             04/03/2022 16:22           4096
drwxr-xr-x vsts             docker             04/03/2022 16:22           4096
drwxr-xr-x vsts             docker             04/03/2022 16:22           4096
drwxr-xr-x vsts             docker             04/03/2022 16:22           4096

    Directory: /home/vsts/work/1/s

UnixMode   User             Group                 LastWriteTime           Size
--------   ----             -----                 -------------           ----
drwxr-xr-x vsts             docker             04/03/2022 16:22           4096
-rw-r--r-- vsts             docker             04/03/2022 16:22           3507
-rw-r--r-- vsts             docker             04/03/2022 16:22           2370
-rw-r--r-- vsts             docker             04/03/2022 16:22           1636
-rw-r--r-- vsts             docker             04/03/2022 16:22           1056
-rw-r--r-- vsts             docker             04/03/2022 16:22         913980

et cetera

    Directory: /home/vsts/work/1/s/src

UnixMode   User             Group                 LastWriteTime           Size
--------   ----             -----                 -------------           ----
drwxr-xr-x vsts             docker             04/03/2022 16:22           4096
drwxr-xr-x vsts             docker             04/03/2022 16:22           4096
drwxr-xr-x vsts             docker             04/03/2022 16:22           4096

et cetera

Why is it not showing file names? How can I ensure that it does?

CodePudding user response:

It looks like the effective console width is 80 characters (as reflected in [Console]::WindowWidth, in which case the Name column doesn't fit and is simply dropped.

Ideally, Azure would allow you to specify a larger console-window width (I don't know if that is an option - do tell us if you know),[1] but a workaround is to pipe to Out-String and use its -Width parameter; e.g.:

- pwsh: Get-ChildItem *.* -Recurse -Path $(Pipeline.Workspace) | Out-String -Width 160
  displayName: 'Show folder contents for debugging'

Note:

  • As the cmdlet's name suggests, it converts Get-ChildItem's output objects to strings, so this is only suitable for capturing for-display representations.

  • As you note, if you don't need all columns, a simpler solution - which additionally avoids stringification - is to pipe to Select-Object; e.g.:

- pwsh: Get-ChildItem *.* -Recurse -Path $(Pipeline.Workspace) | Select-Object UnixMode, Length, Name
  displayName: 'Show folder contents for debugging'

[1] Unfortunately, setting the dimensions of the [Console] class - e.g. [Console]::WindowWidth = 160 is not supported on Unix-like platforms.

  • Related