How to execute Azure DevOps Task extension with powershell 7?

227 Views Asked by At

I have a custom task which basically executes a powershell script. I have been running this with Powershell 5.1 on the build machine, how do I force execute this into Powershell 7?

This calls Powershell 5.1 "execution": { "Powershell": { "target": "widgetUpload.ps1", "argumentFormat": "", "workingDirectory": "$(currentDirectory)" }

Trying to call Powershell 7 with below, but doesn't work.

"execution": { "pwsh": { "target": "widgetUpload.ps1", "argumentFormat": "", "workingDirectory": "$(currentDirectory)" }

We are on TFS 2018.

1

There are 1 best solutions below

0
jessehouwing On

There is no such option. There is no PowerShell Core execution handler.

The only thing you can do is add a wrapper script that calls pwsh from the Windows PowerShell. That's also how the PowerShell@2 tasks does it:

https://github.com/microsoft/azure-pipelines-tasks/blob/a1fb3829bbfe59c6fa0ace05e0f81a52da8fc8db/Tasks/PowerShellV2/powershell.ps1#L149-L180

You should upgrade to the PowerShell3 handler though, but that will still rely on PowerShell 5.1.