我们最近为我们的映像解决方案实现了Azure映像构建器,手动操作一切正常。
1.在AIB模板自定义中,我正在创建一个新文件夹,下载azcopy.exe。
1.在第二次定制中,我传递了一个sas令牌和az copy cmd,以便将大文件从blob下载到新文件夹。
1.另一个ps脚本在最后运行。
现在,当计划与ADO- pipelines集成时,我被困在一个步骤中。在ADO任务中,我正在生成作为参数传递的SAS令牌,但如何在PowerShell内联脚本中传递令牌。
1.要下载Azcopy的定制器。`
{
"type": "PowerShell",
"name": "GetAzCopy",
"inline": [
"New-Item -Type Directory -Path 'c:\\' -Name apps",
"invoke-webrequest -uri 'https://aka.ms/downloadazcopy-v10-windows' -OutFile 'c:\\apps\\azcopy.zip'",
"Expand-Archive 'c:\\apps\\azcopy.zip' 'c:\\apps'",
"copy-item 'C:\\apps\\azcopy_windows_amd64_*\\azcopy.exe\\' -Destination 'c:\\apps'"
]
},`
1.从SAS URI下载大文件的定制器。
`{
"type": "PowerShell",
"name": "downloadapps",
"inline": [
"c:\\apps\\azcopy.exe copy "[parameters('Sasuri')]" c:\\apps\\AVDapps.zip",
"Expand-Archive 'c:\\apps\\AVDapps.zip' c:\\apps"
]
}'
请查看整个json。
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"imageTemplateName": {
"type": "string"
},
"Sasuri": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"name": "[parameters('imageTemplateName')]",
"type": "Microsoft.VirtualMachineImages/imageTemplates",
"apiVersion": "2021-10-01",
"location": "West Europe",
"dependsOn": [],
"tags": {
"imagebuilderTemplate": "win10Pooled",
"userIdentity": "enabled"
},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"identity{}"
}
},
"properties": {
"buildTimeoutInMinutes": 120,
"vmProfile": {
"vmSize": "Standard_D2_v3",
"osDiskSizeGB": 127,
"vnetConfig": {
"name": "networkname",
"subnetName": "subnetname",
"resourceGroupName": "networkresourcegroup",
"subnetId": "subnetid"
}
},
"source": {
"type": "PlatformImage",
"publisher": "MicrosoftWindowsDesktop",
"offer": "office-365",
"sku": "win10-21h2-avd-m365",
"version": "latest"
},
"customize": [
{
"type": "PowerShell",
"name": "GetAzCopy",
"inline": [
"New-Item -Type Directory -Path 'c:\\' -Name apps",
"invoke-webrequest -uri 'https://aka.ms/downloadazcopy-v10-windows' -OutFile 'c:\\apps\\azcopy.zip'",
"Expand-Archive 'c:\\apps\\azcopy.zip' 'c:\\apps'",
"copy-item 'C:\\apps\\azcopy_windows_amd64_*\\azcopy.exe\\' -Destination 'c:\\apps'"
]
},
{
"type": "PowerShell",
"name": "GetArchive",
"inline": [
"c:\\apps\\azcopy.exe copy "[parameters('Fileuri')]" c:\\apps\\AVDapps.zip",
"Expand-Archive 'c:\\apps\\AVDapps.zip' c:\\apps"
]
}
],
"distribute": [
{
"type": "SharedImage",
"galleryImageId": "galleryid",
"location": "westeurope",
"runOutputName": "win10Client",
"artifactTags": {
"source": "azVmImageBuilder",
"baseosimg": "windows10Pooled"
},
"replicationRegions": [
"westeurope"
]
}
]
}
}
]}
'
谢谢纳文
1.我尝试将sasuri作为参数传递给内联powershell脚本,或者尝试使用MSdoc中提到的invoke-webrequest命令
1.在管道本身尝试用早期任务的输出替换值,但没有运气。正如我提到的,手动输入SAS令牌工作正常,没有任何问题。
1条答案
按热度按时间mwg9r5ms1#
最后我成功了:)我没有将sas URI作为参数传递,而是使用了一个powershell任务来替换ADO管道中ARM模板中的文本。((Get-Content -path $MyFile -Encoding UTF8)-replace 'placewhereuneedtoplaceuri',“'FileURI'”)|设置内容$MyFile
这是如此简单,我运行所有职位,以传递/覆盖参数,而不是取代文本与uri为我工作:)职位取代部署模板没有覆盖参数启动部署需要。