azure-pipelines-tasks: Update to Azure Powershell task breaks AzContext in background job

Required Information

Entering this information will route you directly to the right team and expedite traction.

Question, Bug, or Feature?
Type: Bug

Enter Task Name: Azure Powershell

Environment

  • Server - Azure Pipelines or TFS on-premises?

    Azure Pipelines

    • If using Azure Pipelines, provide the account name, team project name, build definition name/build number: Account: amcsgroup Project: Routing Release definition name: routing_qa3_f0 ReleaseId: 4612
  • Agent - Hosted or Private: Hosted

    • If using Hosted agent, provide agent queue name: Azure Pipelines

Issue Description

Since yesterday, 23rd of July, Azure Powershell tasks started failing with an error “Your Azure credentials have not been set up or have expired, please run Connect-AzAccount to set up your Azure credentials.” when passing AzContext to a background job.

Task logs

[Enable debug logging and please provide the zip file containing all the logs for a speedy resolution]

Troubleshooting

Checkout how to troubleshoot failures and collect debug logs: https://docs.microsoft.com/en-us/vsts/build-release/actions/troubleshooting

Error logs

image

Reproduction steps:

  1. Create a release with Azure PowerShell V4 or V5 task using the following params: image

  2. Use the following reproduction script

$Context = Get-AzContext

$ScriptBlock = {
    param($Azcontext)
    $ErrorActionPreference = "Stop"
try {
    Get-AzKeyVault -VaultName %somename% -ResourceGroupName  %some-rg% -AzureRMContext $Azcontext | Out-Null
    Write-Output "Done."
}
catch
{
Write-Error $_
}
}

@(1, 2, 3) | ForEach-Object {
    Start-Job -Name $_ -ScriptBlock $ScriptBlock -ArgumentList $Context | Out-Null
}
Start-Sleep -Seconds 5
@(1, 2, 3) | ForEach-Object {
    Get-Job -Name $_ | Receive-Job
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 21 (6 by maintainers)

Most upvoted comments

Hi All, I have two workarounds that I have tested so far.

  1. Update the task version to 5.* or use AzurePowerShell@5
  2. Run on Windows Powershell (set pwsh: false)