In this series I am going to show you how build a Windows 10 Image via Azure Pipelines and DevOps without 3rd party tooling, welcome to part 1!

Part 1 is about building the Windows 10 machine, sysprepping it and creating an image from it.

Prerequisites

There are some prerequisites.

Firstly, I am assuming that you have knowledge of Azure DevOps. These are the parts that already need be setup:

In addition, if you don’t have knowledge about Azure DevOps and still want to follow this series please let me know. I might write a blog about the preparing Azure DevOps.

Building the Windows 10 Image Pipeline

The pipeline consist of 3 parts:

  • Building a Windows 10 machine using an ARM Template
  • Sysprepping the Windows 10 machine that was just created
  • Creating an image from the just created machine

We are starting with creating the pipeline.

Creating the pipeline

Firstly, log on to the Azure portal.

After that, create a resource group, for example:

  • RG_WE_GoldenImage_WVD

This resourcegroup is for storing the Windows 10 images.

Windows 10 Image Series - Part 1 - Resource Group

Log on to Azure DevOps.

After that, go to your repository and add a new folder:

Windows 10 Image Series - Part 1 - Creating the pipeline

Call the folder ARM templates and put the following file in the folder:

  • Windows10Template.json

Furthermore, you can find this file in my github. Your repo should look like this:

This ARM Template build the Windows 10 Virtual Machine.

Now go to pipelines:

Windows 10 Image Series - Part 1 - Creating the pipeline add

Create a new pipeline:

Windows 10 Image Series - Part 1 - adding the pipeline

Pick “Use the classic editor”:

Windows 10 Image Series - Part 1 - Classic git repo

Select your repository where you have put the ARM Template folder and file:

Windows 10 Image Series - Part 1 - Selecting a source

Lastly, start with an “Empty Job”:

Windows 10 Image Series - Part 1 - Selecting empty job

Name the pipeline and select your agent pool:

Windows 10 Image Series - Part 1 - Naming pipeline and agents

Click on save:

saving  Azure pipeline

The pipeline for Windows 10 Image Series – Part 1 has been created! Let’s go on to the next chapter.

Variable Groups

Next, go to “Library” in the pipelines section:

We are now going to create a variable group where we specify our variables for our build later on. That makes it easier to use the same variables through different scripts and templates.

Please click on “+ Variable Group”:

Name it and add the following variables:

ImageName –> Windows10Image_$(Build.DefinitionName)_$(Build.BuildId) – This is name that the image is going to have
ImageRGName –> RG_WE_GoldenImage_WVD – ResourceGroup where the image is going to land
Location –> WestEurope – Location for all the builds
RGName –> RG_WE_Win10ImageBuild_Temp – Resource Group where the VM is going to build and deleted afterwards
Subnet –> WVD-Build – Subnet where the VM is going to be build in
VNetResourceID –> Put the resource id of your VNET here

After that, click on save!

Next up, go to your Azure Key Vault in the Azure Portal. For example:

Add a secret to this key vault:

Name it: LocalAdminPassword and put a generated password in here:

Go back to Azure DevOps, pipelines, library and add a new variable group:

Name the variable group,

Choose “Link secret from an Azure Key vault as variables”

Pick your service connection and vault

Lastly, add the variables:

Go back to your azure pipeline:

Edit the pipeline:

Click on variables:

And link both variable groups to the pipeline:

This is what it should look like after that:

Filling the pipeline with jobs

It is now time to fill the pipeline with the jobs that handle these tasks:

  • Building a Windows 10 machine using an ARM Template
  • Sysprepping the Windows 10 machine that was just created
  • Creating an image from the just created machine
Building a Windows 10 machine using an ARM Template

Firstly, add the ARM Template job by clicking on this icon:

Adding pipeline jobs

After that, search for “ARM Template deployment” and click on add:

Windows 10 Image Series - Part 1 - Add ARM templatejob

Rename the task and select the deployment scope:

After that, select the “Azure Resource Manager Connection”, “Subscription” and “Action”:

Next, enter a Resource Group name and a location. NOTE: The Resource Group should not exist! This will be automatically cleaned up when the machine has been converted to an image.

It is now time to pick the ARM template to deploy the Windows 10 VM.

Firstly, select “Linked Artifact”:

At the template section select the ARM template we added earlier on in the process. The Windows10template.json file:

Now click on “Override Template Parameters” and make sure to add the following parameters from the variable group created earlier:

Sysprepping the Windows 10 machine that was just created

Add a second job and search for Azure CLI:

Name the task, choos a resource manager connection, script type and a script location:

After that, put the following script in the “Inline Script section”:

This script downloads a sysprep script from my github repository and applies it to the VM. If you are not comfortable using this public script you can also put the sysprep script in a storage account (more information).

Afterwards the ‘CustomScriptExtension’ is removed so you can apply another one later on if you want to.

After this step the VM is sysprepped and ready to be captured.

Creating an image from the just created machine

Add another Azure CLI Job to the pipeline:

Name the task, choos a resource manager connection, script type and a script location:

After that, put the following script in the “Inline Script section”:

This script turns the VM off if it is running and creates a managed image from it. After that, the resource group where the VM was build is removed by this script.

Run the Pipeline

When you are finished creating the pipeline you can click on queue:

The pipeline will start creating the job:

This is the temporary resource group:

These are the temporary resources:

And last but not least there is the image being created:

And the resource group has been removed!

This was Windows 10 Image Series – Part 1, check out the other parts:

(Currently under construction)

References

Other posts:

Autopilot Device info menu script
Powershell function for creating Hostpools

References
Microsoft Docs about AZExtensions

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *