-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to Azure Powershell task breaks AzContext in background job #13348
Comments
Similar result can be achieved by running AzurePowershellV4 with pwsh on Win2016 or Win2019 images `trigger:
pool: steps:
Results: From the commits around this timeframe I haven't found any changes related to the tasks that could cause these responses but it seems similar to #9319 Since V5 outputs the Tls1.2 setting located in the debug for V4 as well because I wasn't sure if this may have an impact ##[debug]TLS 1.2 already present in session. 'Disable-AzContextAutosave' related? |
@20shivangi to check this once |
@PavelPikat Earlier we were using set-azcontext command in the scope of currentUser, due to which all the non-azureps tasks were able to use the Az context so we limited the context to the scope of process. But due to this, some pipelines started breaking where people were using az context created by azureps task. |
Hey guys, that's quite a big bug. We had several pipelines running using this configuration and they all are failing now. E: context is being used in quite a lot of taks. Do you have any workaround, that we can apply so context will still be taken using this task? This change breaks our concept. Thanks, |
@roofiq We ended up adding something like |
Picking up the context in a later step is not the only use-case breaking. An inline script launching another PowerShell.exe fails as well, even though everything is in the same build step. Sure, not the cleanest of things, but not exactly something you expect to break outside a major version update. |
Not sure if this is exactly the same issue, but our pipeline breaks aswell. we have the following task in our pipeline; - task: AzurePowerShell@4
displayName: 'KeyVault'
inputs:
azureSubscription: 'azure environment'
ScriptPath: '$(Pipeline.Workspace)/drop/scripts/Check-KeyVault/Check-KeyVault.ps1'
ScriptArguments: '-KeyVaultName $(keyvaultname)'
azurePowerShellVersion: LatestVersion
pwsh: true The script does one call to Azure $keyVault = Get-AzKeyVault -VaultName $keyVaultName And the pipeline is failing telling us to Run Connect-AzAccount to login. last time it ran the powershell module was version 4.171.1 |
@LeonB87 Are you executing the Az cmdlet in a |
Hi All,
|
@PavelPikat The powershell script itself doesn't contain a scriptblock. param(
[string][parameter(Mandatory = $true)] $keyVaultName
)
$keyVault = Get-AzKeyVault -VaultName $keyVaultName
if ($keyvault) {
Write-Host "##vso[task.setvariable variable=keyVaultExists]true"
Write-Output "Variable for keyvault is set to true".
} else {
Write-Host "##vso[task.setvariable variable=keyVaultExists]false"
Write-Output "Variable for keyvault is set to false".
} |
Hey. So if you disable Powershell Core on this task, it will run as before this change. Powershell core is creating another process which is loosing the context and all. |
The initial issue I created, including its repro steps use v5 without PowerShell Core, so if anything changed now, then it must be due to some fix. I'll re-test my code again |
Tested work arounds mentioned by v-kyljon on my side. AzurePowerShell@5 using Core works, aswell as AzurePowerShell@4 Without Core. |
Yeah, seems like it's fixed now. The old release still fails, but if I create new deployment using the same task and code, then it seem to work. |
@PavelPikat Can you let me know the version of task in which issue is not occuring now ? |
@roofiq I am trying to understand the scenario - what do you mean by "Even when we are uploading ARM templates to storage account,"....which task are you using to upload the template ? |
@chshrikh, nevermind because it all works when disabling Core in v4. But we are uploading ARM templates to storage with Azure PowerShell task so it was all connected :) |
I think I'm having this error too. Switching to version 5.* doesn't seem to have helped. The error I get from my background job is |
@harre096 are you still facing this issue? we have reverted our changes. |
For my script that uses background jobs and runs in AzureDevops. I have been using 5.* successfully for a while. I tested 4.* today and that seems to be working again too. |
Thanks for confirming. Closing this 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
Account: amcsgroup
Project: Routing
Release definition name: routing_qa3_f0
ReleaseId: 4612
Agent - Hosted or Private:
Hosted
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
Reproduction steps:
Create a release with Azure PowerShell V4 or V5 task using the following params:

Use the following reproduction script
The text was updated successfully, but these errors were encountered: