Reputation: 377
I'm trying to write a script that I can automate on Azure to create a new instance of a cloud service. I am having trouble getting the New-AzureDeployment cmdlet to work.
Both the CSPKG and CSCFG files are stored on Azure under the same storage account but in different containers. They were uploaded using CloudBerry.
param(
[parameter(Mandatory=$False)]
[string] $StorageAccount = 'storageaccount',
[parameter(Mandatory=$False)]
[string] $ServiceName = 'cloudservicesdev',
[parameter(Mandatory=$False)]
[string] $Slot = 'Production',
[parameter(Mandatory=$False)]
[string] $Label = 'BASE'
)
Write-Output "Start of workflow"
$cert = Get-AutomationCertificate -Name 'Credential'
$subID = 'subId'
Set-AzureSubscription -SubscriptionName "SubName" -CurrentStorageAccountName $StorageAccount -Certificate $cert -SubscriptionId $subID
Select-AzureSubscription "SubName"
$package = (Get-AzureStorageBlob -blob "package.cspkg" -Container "package").ICloudBlob.uri.AbsoluteUri
$config = (Get-AzureStorageBlob -blob "Config - Dev.cscfg" -Container "config").ICloudBlob.uri.AbsoluteUri
New-AzureDeployment -ServiceName "$ServiceName" -Slot "$Slot" -Package "$package" -Configuration "$config" -Label "$Label"
I get the following error
2014-12-08 05:57:57 PM, Error: New-AzureDeployment : The given path's format is not supported.
At Create_New_Cloud_Service_Instance:40 char:40
+
+ CategoryInfo : NotSpecified: (:) [New-AzureDeployment], NotSupportedException
+ FullyQualifiedErrorId :
System.NotSupportedException,Microsoft.WindowsAzure.Commands.ServiceManagement.HostedServices.NewAzureDeploymentCommand
I've checked both the $package and $config variables and they are pointing to the file locations I'd expect (https://storageaccount.blob.core.windows.net/package/package.cspkg and https://storageaccount.blob.core.windows.net/config/Config%20-%20Dev.cscfg respectively). They match the URLs I see when I navigate to the files under their containers in Storage.
This looks similar to the examples that I have seen. What have I done wrong?
This is the new code that I used based on Joe's answer below
I also used this example script https://gallery.technet.microsoft.com/scriptcenter/Continuous-Deployment-of-A-eeebf3a6 to help with the using the Azure Automation sandbox
param(
[parameter(Mandatory=$False)]
[string] $StorageAccount = 'storageaccount',
[parameter(Mandatory=$False)]
[string] $ServiceName = 'cloudservicesdev',
[parameter(Mandatory=$False)]
[string] $Slot = 'Production',
[parameter(Mandatory=$False)]
[string] $Label = 'BASE'
)
Write-Output "Start of workflow"
$cert = Get-AutomationCertificate -Name 'Credential'
$subID = 'subId'
Set-AzureSubscription -SubscriptionName "SubName" -CurrentStorageAccountName $StorageAccount -Certificate $cert -SubscriptionId $subID
Select-AzureSubscription "SubName"
$package = (Get-AzureStorageBlob -blob "package.cspkg" -Container "package").ICloudBlob.uri.AbsoluteUri
$TempFileLocation = "C:\temp\Config - Dev.cscfg"
$config = (Get-AzureStorageBlobContent -blob "Config - Dev.cscfg" -Container "config" -Destination $TempFileLocation -Force)
New-AzureDeployment -ServiceName "$ServiceName" -Slot "$Slot" -Package "$package" -Configuration $TempFileLocation -Label "$Label"
Upvotes: 2
Views: 1356
Reputation: 2540
The -Package parameter of New-AzureDeployment should be passed a storage URI as you are doing, but the -Configuration parameter expects a local file. See http://msdn.microsoft.com/en-us/library/azure/dn495143.aspx for more details.
So you need to, within the runbook, download the file at the $config URI to the Azure Automation sandbox, and then pass that file's local path to New-AzureDeployment.
Upvotes: 3