How to use json files and Azure Image builder

SenhorDolas 1,326 Reputation points
2022-02-22T11:50:50.797+00:00

Hi
I have been using Azure Image Builder agent from DevOps to deploy my images however my region UKSouth is not available on the agent and this delays the process as it has to copy from NorthEurope into UKsouth region.

I know I can use azimagebuilder commands and the scripts that Jason made a long time agon but is there a way to reproduce my sets from the agent gui builder into json?

I cannot figure out a way

This is my yaml:

> steps:

- task: AzureImageBuilder.devOps-task-for-azure-image-builder.custom-build-release-task.AzureImageBuilderTask@1
  displayName: 'Azure VM Image Builder Task'
  inputs:
    managedIdentity: '/subscriptions/cxxx/resourceGroups/wvdImageDemoRg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/aibIdentity1xxx'
    imageSource: marketplace
    baseImagePubOfferSku: 'MicrosoftWindowsDesktop:office-365:win10-21h2-avd-m365'
    provisioner: powershell
    windowsUpdateProvisioner: true
    runElevated: true
    runAsSystem: true
    packagePath: '$(System.DefaultWorkingDirectory)/_xGEN_Repo'
    inlineScript: |
     & 'C:\buildartifacts\_xGEN_Repo\Main_Script.ps1'
     & 'C:\buildartifacts\__xGEN_Repo\CS_Install_Choco.ps1'
     & 'C:\buildartifacts\__xGEN_Repo\CS_Install_Chocolatey_Apps.ps1'
     & 'C:\buildartifacts\__xGEN_Repo\CS_Install_LanguagePack.ps1'
     & 'C:\buildartifacts\__xGEN_Repo\CS_Install_MSTeams.ps1'
     & 'C:\buildartifacts\__xGEN_Repo\CS_Install_Sophos.ps1'
     & 'C:\buildartifacts\__xGEN_Repo\CS_Virtual-Desktop-Optimization-Tool-main_v3.ps1'
    storageAccountName: xxwvdimagedemostoracc
    distributeType: sig
    galleryImageId: '/subscriptions/cxxx/resourceGroups/wvdImageDemoRg/providers/Microsoft.Compute/galleries/myaibsig01/images/win10wvd'
    replicationRegions: uksouth
    ibSubscription: 'my subs (cxxx)'
    ibAzureResourceGroup: wvdImageDemoRg
    ibLocation: northeurope
    vmSize: 'Standard_D2_v5'

Any help is appreciated.

Thanks M

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,018 questions
Community Center | Not monitored
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2025-03-05T21:45:32.2766667+00:00

    From what you shared, I understand that your YAML defines a DevOps pipeline step using the AzureImageBuilderTask@1 task, which translates into an Azure Image Builder template.

    The JSON equivalent of this YAML file follows the structure expected by Azure VM Image Builder API.

    Azure Image Builder JSON format includes:

    • properties (describes source image, customization, distribution)
    • source (marketplace image details)
    • customize (PowerShell scripts and configurations)
    • distribute (Shared Image Gallery details)
    • replicationRegions (where the final image is available)

    Online tools like yaml2json can help, but manual adjustments will still be needed.

    {
    
      "location": "northeurope",
    
      "properties": {
    
        "buildTimeoutInMinutes": 120,
    
        "vmProfile": {
    
          "vmSize": "Standard_D2_v5",
    
          "osDiskSizeGB": 127
    
        },
    
        "source": {
    
          "type": "PlatformImage",
    
          "publisher": "MicrosoftWindowsDesktop",
    
          "offer": "office-365",
    
          "sku": "win10-21h2-avd-m365",
    
          "version": "latest"
    
        },
    
        "customize": [
    
          {
    
            "type": "PowerShell",
    
            "name": "Run Custom Scripts",
    
            "runElevated": true,
    
            "inline": [
    
              "C:\\buildartifacts\\_xGEN_Repo\\Main_Script.ps1",
    
              "C:\\buildartifacts\\__xGEN_Repo\\CS_Install_Choco.ps1",
    
              "C:\\buildartifacts\\__xGEN_Repo\\CS_Install_Chocolatey_Apps.ps1",
    
              "C:\\buildartifacts\\__xGEN_Repo\\CS_Install_LanguagePack.ps1",
    
              "C:\\buildartifacts\\__xGEN_Repo\\CS_Install_MSTeams.ps1",
    
              "C:\\buildartifacts\\__xGEN_Repo\\CS_Install_Sophos.ps1",
    
              "C:\\buildartifacts\\__xGEN_Repo\\CS_Virtual-Desktop-Optimization-Tool-main_v3.ps1"
    
            ]
    
          },
    
          {
    
            "type": "WindowsUpdate",
    
            "searchCriteria": "IsInstalled=0",
    
            "filters": ["exclude:KB123456"],
    
            "updateLimit": 40
    
          }
    
        ],
    
        "distribute": [
    
          {
    
            "type": "SharedImageGallery",
    
            "galleryImageId": "/subscriptions/cxxx/resourceGroups/wvdImageDemoRg/providers/Microsoft.Compute/galleries/myaibsig01/images/win10wvd",
    
            "replicationRegions": ["uksouth"],
    
            "runOutputName": "myImageOutput"
    
          }
    
        ],
    
        "identity": {
    
          "type": "UserAssigned",
    
          "userAssignedIdentities": {
    
            "/subscriptions/cxxx/resourceGroups/wvdImageDemoRg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/aibIdentity1xxx": {}
    
          }
    
        }
    
      }
    
    }
    
    

    Once you create the JSON file (aib-template.json), deploy it using Azure CLI:

    az resource create \
    
      --resource-group wvdImageDemoRg \
    
      --properties @aib-template.json \
    
      --is-full-object \
    
      --resource-type Microsoft.VirtualMachineImages/imageTemplates \
    
      --name MyImageTemplate
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.