Reputation: 13
We recently implemented Azure image builder for our image solution, everything is working fine manually.
Now when planned to integrate with ADO- pipelines, I am stuck at one step. in ADO task, I am generating the sas token to pass as a parameter, but how to pass the token inside the powershell inline script.
{
"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": "downloadapps",
"inline": [
"c:\\apps\\azcopy.exe copy "[parameters('Sasuri')]" c:\\apps\\AVDapps.zip",
"Expand-Archive 'c:\\apps\\AVDapps.zip' c:\\apps"
]
} `
Please review the whole 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"
]
}
]
}
}
]}
`
Thank you. Naveen.
Upvotes: 0
Views: 564
Reputation: 13
Finally I got it working :) Instead of passing sas URI as a parameter, I have used a powershell task to replace the text in the ARM template in ADO pipeline.
((Get-Content -path $MyFile -Encoding UTF8 ) -replace 'placewhereuneedtoplaceuri',"'FileURI'") | Set-Content $MyFile
It was so simple, I was running around all posts to pass/override the parameters instead replacing the text with the uri worked for me. Post replacing, deploying the template without override parameters initiated the deployment as needed.
Upvotes: 0