question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update to Azure Powershell task breaks AzContext in background job

See original GitHub issue

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
}

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
v-kyljoncommented, Jul 27, 2020

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)
0reactions
AmrutaKawadecommented, Aug 28, 2020

Thanks for confirming. Closing this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run Azure PowerShell cmdlets in PowerShell Jobs
Learn how to run Azure PowerShell cmdlets in parallel or as background tasks, using -AsJob and Start-Job.
Read more >
Azure DevOps pipeline, Azure PowerShell 4.* script loses ...
I've found reference to changes made in the Azure PowerShell DevOps task, that the context needs to be passed explicitly to background tasks...
Read more >
In-Depth Guide to Building a PowerShell Pipeline in Azure ...
Tasks are the building blocks of Azure DevOps (AzDo) pipelines. ... natively run three types of scripts – PowerShell, Bash, and batch files....
Read more >
In Azure Pipelines, How To Execute A Background Task While ...
Coming from a DevOps background having switched to SWE 3 years ago Git ... Update to Azure Powershell task breaks AzContext in background...
Read more >
custom/Update-AzFunctionApp.ps1 1.0.1 - PowerShell Gallery
Azure.PowerShell.Cmdlets.Functions.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')] [ValidateNotNullOrEmpty()] [System.String]
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found