当由 C# 完成时,文件将在“TaskCompletion”之后上传到存储容器,但在 Azure-RM PowerShell 中完成相同操作时,即使任务成功并生成输出文件,也不会将输出文件上传到存储容器。
我参考了Microsoft Docs for Azure RM PowerShell 6.13.0。我尝试将 ResourceFiles 和 OutputFiles 作为列表提供。资源文件正在节点上下载,但在任务完成后,输出文件没有上传。我尝试将 FilePattern 更改为“*.zip”、“Output_00001.zip”,但没有成功。
我在 Batch Explorer 中注意到配置 JSON 在由 Azure RM 运行时具有空的输出文件数组。但是当由 C# 运行时,配置 JSON 中有输出文件。
"resourceFiles": [
{
"httpUrl": "https://teststorage.blob.core.windows.net/sku-test/Input_00001.zip?sv=2018-03-28&sr=b&sig=iY7lr8QyYzev2Eg1234562BG11ETHftTD8hzZR123456%3D&se=2019-08-26T07%3A10%3A11Z&sp=rwdl",
"filePath": "Input_00001.zip"
},
{
"httpUrl": "https://teststorage.blob.core.windows.net/sku-test/AppConfig.xml?sv=2018-03-28&sr=b&sig=QbSAAsi9gZdU6bS7yoBIvr123456ratH2wC2l123456%3D&se=2019-08-26T06%3A08%3A58Z&sp=r",
"filePath": "AppConfig.xml"
},
{
"httpUrl": "https://teststorage.blob.core.windows.net/sku-test/Task.ps1?sv=2018-03-28&sr=b&sig=re3Cn8pY4123456DRSt8kn3PHF81FSiJ3zIt7123456%3D&se=2019-08-26T06%3A08%3A58Z&sp=r",
"filePath": "Task.ps1"
}
],
"outputFiles": [],
当由 C# 完成时:
"resourceFiles": [
{
"autoStorageContainerName": "cdfb56e1-b421-4f06-9ef5-0de18ea288d8",
"blobPrefix": "AppConfig.config"
},
{
"autoStorageContainerName": "cdfb56e1-b421-4f06-9ef5-0de18ea288d8",
"blobPrefix": "Task.ps1"
},
{
"autoStorageContainerName": "cdfb56e1-b421-4f06-9ef5-0de18ea288d8",
"blobPrefix": "Input_00001.zip"
}
],
"outputFiles": [
{
"filePattern": "Output_00001.zip",
"destination": {
"container": {
"containerUrl": "https://teststorage.blob.core.windows.net/cdfb56e1-b421-4f06-9ef5-0de18ea288d8?sv=2018-11-09&sr=c&sig=p2GJGkCmxJAEpJr%2BlwkUTEZjD2GZcGoUpl4Am79YQyM%3D&se=2019-08-25T21%3A32%3A19Z&sp=w"
}
},
"uploadOptions": {
"uploadCondition": "TaskCompletion"
}
}
],
这是 PowerShell 脚本:
$uploadOptions = New-Object Microsoft.Azure.Commands.Batch.Models.PSOutputFileUploadOptions "TaskCompletion";
$OutputSasToken = New-AzureStorageContainerSASToken -Context $StorageContext -Name $StorageContainerName -FullUri -Permission w;
foreach ($blob in $Blobs) {
$SasToken = New-AzureStorageBlobSASToken -ICloudBlob $blob.ICloudBlob -Context $StorageContext -Permission rwdl -FullUri;
$blobName = $blob.Name;
if($blobName.Contains(".zip") -and $blobName.Contains("Input_")) {
$ResourceFile = New-Object Microsoft.Azure.Commands.Batch.Models.PSResourceFile -ArgumentList @($SasToken, $blobName);
$TaskName = "Task_" + $blobName.Replace(".zip", "").Replace("Input_", "");
$OutputFile = "Output_" + $blobName.Replace("Input_", "");
$Task = New-Object Microsoft.Azure.Commands.Batch.Models.PSCloudTask($TaskName, "cmd /S /C `"powershell -f $AppPsFile -configurationFileName $AppConfigFile -inputArchiveName $blobName -outputArchiveName $OutputFile -archiveKey $EncryptionKey");
$Task.ResourceFiles = New-Object System.Collections.Generic.List``1[Microsoft.Azure.Commands.Batch.Models.PSResourceFile];
$Task.ResourceFiles.Add($ResourceFile);
$Task.ResourceFiles.Add($cResourceFile);
$Task.ResourceFiles.Add($PsScriptResourceFile);
$blobContainerDestination = New-Object Microsoft.Azure.Commands.Batch.Models.PSOutputFileBlobContainerDestination $OutputSasToken;
$destination = New-Object Microsoft.Azure.Commands.Batch.Models.PSOutputFileDestination $blobContainerDestination;
$OutputFileToUpload = New-Object Microsoft.Azure.Commands.Batch.Models.PSOutputFile $OutputFile, $destination, $uploadOptions;
$Task.OutputFiles = New-Object System.Collections.Generic.List``1[Microsoft.Azure.Commands.Batch.Models.PSOutputFile];
$Task.OutputFiles.Add($OutputFileToUpload);
$Tasks += @($Task);
}
}
New-AzureBatchPool -Id $PoolId -VirtualMachineSize $VmSize -VirtualMachineConfiguration $configuration -AutoScaleFormula $AutoScaleFormula -BatchContext $BatchAccount -DisplayName $DisplayName -NetworkConfiguration $networkConfig;
New-AzureBatchJob -Id $JobId -PoolInformation $PoolInformation -BatchContext $BatchAccount;
$Job = Get-AzureBatchJob -BatchContext $BatchAccount -Id $JobId
New-AzureBatchTask -Job $Job -Tasks $Tasks -BatchContext $BatchAccount #Here the tasks are added after Pool, Job are created
如何添加输出文件列表?