Azure account import

By default octopus deploy (3.xx) injects azure account into powershell runspace, so having created the azure account based on certificate I can easily use Azure cmdlets inside my powershell script (one of deployment steps). But now, inside that script I want to run some functions in parallel. Powershell has “workflow” for these purposes. The problem is that I don’t know how to initialize azure account from inside of workflow. The error I receive when i use azure cmdlets from inside the workflow is “No default subscription has been
11:03:09Error
designated. Use Select-AzureSubscription -Default to set
11:03:09Error
the default subscription.”

Here is the quick code to repro:

Workflow GetWebJobs {
param([string[]] $websiteNames)
ForEach -Parallel ($websiteName in $websiteNames) {
Get-AzureWebsiteJob -Name $websiteName
}
}

$websiteNames = "some azure website name"
Get-AzureAccount

GetWebJobs -websiteNames $websiteNames

How can I import azure account inside of a workflow?

Because octopus injects some variables into runspace, here is the workaround:

Workflow GetWebJobs {
param([string[]] $websiteNames, $subscription, $cert)
Set-AzureSubscription –SubscriptionName $subscription.SubscriptionName –SubscriptionId $subscription.SubscriptionId -Certificate $cert
Select-AzureSubscription -Current -SubscriptionName $subscription.SubscriptionName
ForEach -Parallel ($websiteName in $websiteNames) {
Get-AzureWebsiteJob -Name $websiteName
}
}
$subscription = Get-AzureSubscription
$websiteNames = “some website name”

GetWebJobs -websiteNames $websiteNames $subscription $certificate

Hi Serg,

It sounds like you’ve had some success; I’m glad to hear it.

If there’s anything we can help with, you know where to find us.

Michael