使用Azure Automation使用Powershell创建云服务实例

时间:2014-12-08 18:16:38

标签: azure azure-storage azure-powershell azure-automation

我正在尝试编写一个脚本,我可以在Azure上自动创建一个新的云服务实例。我无法使New-AzureDeployment cmdlet正常工作。

CSPKG和CSCFG文件都存储在Azure上的相同存储帐户下,但存储在不同的容器中。他们是使用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"

我收到以下错误

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

我检查了$ package和$ config变量,它们指向我期望的文件位置(分别为https://storageaccount.blob.core.windows.net/package/package.cspkghttps://storageaccount.blob.core.windows.net/config/Config%20-%20Dev.cscfg)。它们与我在导航到容器中的文件时看到的URL匹配。

这与我见过的例子类似。我做错了什么?

这是我根据Joe的回答

使用的新代码

我还使用此示例脚本https://gallery.technet.microsoft.com/scriptcenter/Continuous-Deployment-of-A-eeebf3a6来帮助使用Azure自动化沙箱

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"

1 个答案:

答案 0 :(得分:3)

New-AzureDeployment的-Package参数应该像您一样传递存储URI,但-Configuration参数需要本地文件。有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/azure/dn495143.aspx

因此,您需要在Runbook中将$ config URI下的文件下载到Azure自动化沙箱,然后将该文件的本地路径传递给New-AzureDeployment。