【问题标题】:Azure WebJob with Powershell Script to upload file to Azure Blob storage使用 Powershell 脚本将文件上传到 Azure Blob 存储的 Azure WebJob
【发布时间】:2016-11-15 15:44:50
【问题描述】:

我正在尝试将 powershell 脚本作为 Azure Web 作业(WebApps 附带的简单作业)运行,该脚本负责创建 PDF 文件并将该文件上传到 Azure Blob 存储。成功创建文件后,使用以下命令上传文件时出错:

$pdfFileName = $reportId + ".pdf";
$storageAccountName = "MY-STORE"
$storageAccountKey = "MY-KEY"
$containerName = "_MY_CONTAINER"
$fullFileName = $PSScriptRoot + "\" + $pdfFileName

$ctx = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
Set-AzureStorageBlobContent -File "$fullFileName" -Container $containerName -Blob $pdfFileName -Context $ctx -Force

因此,我在 Azure Web Jobs 日志(在 Kudu 门户中)中显示了以下消息。

[11/15/2016 15:20:24 > 89499f: ERR ] Set-AzureStorageBlobContent : Win32 internal error "The handle is invalid" 0x6 
[11/15/2016 15:20:24 > 89499f: ERR ] occurred while reading the console output buffer. Contact Microsoft Customer 
[11/15/2016 15:20:24 > 89499f: ERR ] Support Services.
[11/15/2016 15:20:24 > 89499f: ERR ] At 
[11/15/2016 15:20:24 > 89499f: ERR ] D:\local\Temp\jobs\triggered\ddd\orgmoz1g.dqi\generateAndUploadReports.ps1:53 
[11/15/2016 15:20:24 > 89499f: ERR ] char:3
[11/15/2016 15:20:24 > 89499f: ERR ] +      Set-AzureStorageBlobContent -File $fullFileName -Container 
[11/15/2016 15:20:24 > 89499f: ERR ] $containerName -Blo ...
[11/15/2016 15:20:24 > 89499f: ERR ] +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[11/15/2016 15:20:24 > 89499f: ERR ] ~~~~~~
[11/15/2016 15:20:24 > 89499f: ERR ]     + CategoryInfo          : ReadError: (:) [Set-AzureStorageBlobContent], Ho 
[11/15/2016 15:20:24 > 89499f: ERR ]    stException
[11/15/2016 15:20:24 > 89499f: ERR ]     + FullyQualifiedErrorId : ReadConsoleOutput,Microsoft.WindowsAzure.Command 
[11/15/2016 15:20:24 > 89499f: ERR ]    s.Storage.Blob.SetAzureBlobContentCommand

相同的脚本在我的本地机器上正常工作。更重要的是,当我创建 webjob 只是为了使用 Get-Module -ListAvailable 列出可用模块时,我还收到了带有以下模块的模块。

    ...
[11/15/2016 15:40:36 > 89499f: INFO] ModuleType Version    Name                                ExportedCommands     
[11/15/2016 15:40:36 > 89499f: INFO] ---------- -------    ----                                ----------------     
[11/15/2016 15:40:36 > 89499f: INFO] Manifest   1.4.0      Azure                               {Get-AzureAutomati...
...
[11/15/2016 15:40:36 > 89499f: INFO] ModuleType Version    Name                                ExportedCommands     
[11/15/2016 15:40:36 > 89499f: INFO] ---------- -------    ----                                ----------------     
[11/15/2016 15:40:36 > 89499f: INFO] Manifest   1.1.2      Azure.Storage                       {Get-AzureStorageB...
...

【问题讨论】:

    标签: powershell azure azure-storage azure-webjobs


    【解决方案1】:

    根据您的描述,我可以重现您的问题。经过一些试验,我认为这是由于PowerShell Progress Indicators 在长时间运行的操作期间在 UI 中提供了进度指示器。在调用Set-AzureStorageBlobContent 之前,您可以尝试通过执行以下命令来禁用 Power Shell 中的进度指示器:

    $ProgressPreference="SilentlyContinue"

    【讨论】:

    • 原因是shell的远程Web UI无法投射进度条,请在每次刷新或导航到基于SCM web的PS控制台时禁用。参考这个问题:github.com/projectkudu/kudu/issues/2172
    • Bruce 提出的解决方案正是我想要的。现在一切正常。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2017-01-24
    • 2017-08-19
    • 2021-06-20
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多