Search code examples
azure-devopsazure-pipelinesazure-powershellazure-pipelines-build-task

AzurePowerShell@5 is failing to find parameter FederatedToken


I'm using the - task: AzurePowerShell@5 in an Azure DevOps pipeline using Azure PowerShell version 2.6.0: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-powershell-v5?view=azure-pipelines

The azureSubscription is set to an Azure DevOps service connection authenticating using a federated credential.

The AzurePowerShell@5 task fails when it runs Connect-AzAccount to authenticate.

Connect-AzAccount fails with the following error:

A parameter cannot be found that matches parameter name 'FederatedToken'.

FederatedToken should be a supported parameter based off this document: https://learn.microsoft.com/en-us/powershell/module/az.accounts/connect-azaccount?view=azps-11.6.0

A more verbose log:

##[debug]Connect-AzAccount: D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.239.9\ps_modules\VstsAzureHelpers_\InitializeAzModuleFunctions.ps1:438
##[debug]Line |
##[debug] 438 |              & $command @args
##[debug]     |                         ~~~~~
##[debug]     | A parameter cannot be found that matches parameter name 'FederatedToken'.

It could be the case that the PowerShell version 2.6.0 doesn't support FederatedToken as a parameter but I don't see any documentation indicating that information.


Solution

  • I can reproduce the issue when the version of azurePowerShellVersion is 2.6.0, which has been out of support since at least 2020. According to the official documentation for the Azure PowerShell Support Lifecycle,

    The Az PowerShell modules support lifecycle falls under the Azure SDK lifecycle policy. We support the last two minor versions of the current major version and last minor version of the previous major version of the Az PowerShell module.

    Currently, the default version of the Az PowerShell module on Windows and Ubuntu images is 11.3.1. (See the default software on MS-hosted agent here). Testing with 11.3.1, it works fine.

    pool:
      vmImage: windows-latest
    
    steps:
    - task: AzurePowerShell@5
      inputs:
        azureSubscription: '${{ parameters.AzureSubscription }}'
        ScriptType: 'InlineScript'
        Inline: 'Save-AzContext -Path <pathname>'
        FailOnStandardError: true
        azurePowerShellVersion: 'LatestVersion'
        pwsh: true
    

    enter image description here

    So far, the latest version of Azure PowerShell is 11.6.0. You can use it in the pipeline via preferredAzurePowerShellVersion: '11.6.0'.