3 Azure PowerShell How to run background Jobs
Vincent A (vinca) редактировал(а) эту страницу 2019-02-12 07:52:41 +05:30

Azure PowerShell task sets the context in Process scope instead of user scope. This is to ensure that the context is not leaked outside the current task.

Now, the context need to be explicitly passed for all background jobs. Follow the below step to pass context to background job:

Save the context to a file and then import the context in each background job.

Save-AzureRmContext -Path "$(Agent.TempDirectory)/myContext.json"
Start-Job -Job {
    Import-AzureRmContext -Path "$(Agent.TempDirectory)/myContext.json"
    Set-AzureRmContext -SubscriptionName "<sub_name>"
    # --- your powershell commands here ---
}

[Reference]