azure - 使用 Azure 自动化使用 Powershell 创建云服务实例

标签 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"

最佳答案

应像您所做的那样向 New-AzureDeployment 的 -Package 参数传递存储 URI,但 -Configuration 参数需要本地文件。请参阅http://msdn.microsoft.com/en-us/library/azure/dn495143.aspx了解更多详情。

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

关于azure - 使用 Azure 自动化使用 Powershell 创建云服务实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27364286/

相关文章:

angular - 无法使用 azure-sdk-for-js 通过 Angular 访问 Azure Data Lake Gen2 的文件系统

caching - 如何检查redis缓存表是否为空?

azure - terraform 嵌套在 azure 存储帐户中的每个循环

postgresql - 将 azure 文件存储与 kubernetes 和 azure 容器服务 (aks) 一起使用 - 权限被拒绝

ios - 如果我在从azure服务同步(增量同步)时增加页面大小,有什么缺点

javascript - 使用 Azure 媒体服务直播单个/静态音频文件

c# - 分区键的天蓝色存储大小超出范围?

azure - 保存-AzureWebSiteLog 调用-WebRequest 错误

azure - 获取 AzureKeyVaultSecret : Operation returned an invalid status code 'Forbidden'

azure - Powershell Connect-AzureAD 错误 "accessing_ws_metadata_exchange_failed"