Skip to content

Commit 9ee3515

Browse files
Merge pull request #302914 from v-albemi/image-factory-retention
Freshness: Azure DevTest Labs - Set 2 of 2
2 parents 941625f + b55b60f commit 9ee3515

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed
Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,71 @@
11
---
2-
title: Set up retention policy
3-
description: Learn how to configure a retention policy, clean up the factory, and retire old images from DevTest Labs.
2+
title: Set Up an Image Retention Policy
3+
description: Learn how to configure an image retention policy, clean up an image factory, and retire old images in DevTest Labs.
44
ms.topic: how-to
55
ms.author: rosemalcolm
66
author: RoseHJM
7-
ms.date: 06/26/2020
7+
ms.date: 07/21/2025
88
ms.custom: UpdateFrequency2
9+
10+
#customer intent: As a lab admin, I want to set up an image retention policy in DevTest Labs so that I can periodically clean my image factory.
911
---
1012

11-
# Set up retention policy in Azure DevTest Labs
12-
This article covers setting a retention policy, cleaning up the factory, and retiring old images from all the other DevTest Labs in the organization.
13+
# Set up an image retention policy in Azure DevTest Labs
1314

14-
## Prerequisites
15-
Make sure that you follow these articles before proceeding further:
15+
This article covers setting an image retention policy, cleaning up an image factory, and retiring old images from all the DevTest labs in an organization.
1616

17-
- [Create an image factory](image-factory-create.md)
18-
- [Run an image factory from Azure DevOps](image-factory-set-up-devops-lab.md)
19-
- [Save custom images and distribute to multiple labs](image-factory-save-distribute-custom-images.md)
17+
## Prerequisites
2018

21-
The following items should already be in place:
19+
- A lab for the image factory in Azure DevTest Labs.
20+
- One or more target DevTest labs where the factory will distribute golden images.
21+
- An Azure DevOps project to automate the image factory.
22+
- A source code location that contains the scripts and configuration. (It can be DevOps project noted in the preceding prerequisite.)
23+
- Completion of the steps in these articles:
24+
- [Create an image factory](image-factory-create.md)
25+
- [Run an image factory from Azure DevOps](image-factory-set-up-devops-lab.md)
26+
- [Save custom images and distribute to multiple labs](image-factory-save-distribute-custom-images.md)
2227

23-
- A lab for the image factory in Azure DevTest Labs
24-
- One or more target Azure DevTest Labs where the factory will distribute golden images
25-
- An Azure DevOps Project used to automate the image factory.
26-
- Source code location containing the scripts and configuration (in our example, in the same DevOps Project used above)
27-
- A build definition to orchestrate the Azure PowerShell tasks
28-
2928
## Setting the retention policy
30-
Before you configure the cleanup steps, define how many historic images you want to keep in DevTest Labs. When you followed the [Run an image factory from Azure DevOps](image-factory-set-up-devops-lab.md) article, you configured various build Variables. One of them was **ImageRetention**. You set this variable to `1`, which means that the DevTest Labs won't maintain a history of custom images. Only the latest distributed images will be available. If you change this variable to `2`, the latest distributed image plus the previous ones will be maintained. You can set this value to define the number of historic images you want to maintain in your DevTest Labs.
3129

32-
## Cleaning Up the factory
33-
The first step in cleaning Up the factory is to remove the golden Image VMs from the image factory. There's a script to do this task just like our previous scripts. The first step is to add another **Azure PowerShell** task to the build definition as shown in the following image:
30+
Before you configure the cleanup steps, define how many historic images you want to keep in DevTest Labs. The [Run an image factory from Azure DevOps](image-factory-set-up-devops-lab.md) article describes how to configure various build variables, including `ImageRetention`. If you set this variable to `1`, DevTest Labs doesn't maintain a history of custom images. Only the latest distributed images are available. If you set this variable to `2`, the latest distributed image plus and the previous ones are maintained. You can set this value to define the number of historic images you want to maintain in DevTest Labs.
31+
32+
## Cleaning up a factory
3433

35-
![Screenshot that shows a PowerShell step.](./media/set-retention-policy-cleanup/powershell-step.png)
34+
The first step in cleaning up a factory is to remove the golden image VMs from the image factory. There's a script that does this task. First, you need to add another Azure PowerShell task to the build definition, as shown in the following image:
3635

37-
Once you have the new task in the list, select the item, and fill in all the details as shown in the following image:
36+
:::image type="content" source="./media/set-retention-policy-cleanup/powershell-step.png" alt-text="Screenshot that shows the steps for adding a PowerShell task." lightbox="./media/set-retention-policy-cleanup/powershell-step.png":::
3837

39-
![Screenshot that shows the Clean up old images PowerShell task.](./media/set-retention-policy-cleanup/configure-powershell-task.png)
38+
After you have the new task in the list, select the item, and then provide the details shown here:
4039

41-
The script parameters are: `-DevTestLabName $(devTestLabName)`.
40+
:::image type="content" source="./media/set-retention-policy-cleanup/configure-powershell-task.png" alt-text="Screenshot that shows the details for the PowerShell task." lightbox="./media/set-retention-policy-cleanup/configure-powershell-task.png":::
41+
42+
The script parameters are:
43+
`-DevTestLabName $(devTestLabName)`
4244

4345
## Retire old images
44-
This task removes any old images, keeping only a history matching the **ImageRetention** build variable. Add an additional **Azure PowerShell** build task to our build definition. Once it's added, select the task, and fill in the details as shown in the following image:
4546

46-
![Screenshot that shows Retire old images PowerShell task.](./media/set-retention-policy-cleanup/retire-old-image-task.png)
47+
This task removes any old images, keeping only a history, based on the setting in the `ImageRetention` build variable. Add an additional Azure PowerShell build task to the build definition. After it's added, select the task, and then provide the details shown here:
4748

48-
The script parameters are: `-ConfigurationLocation $(System.DefaultWorkingDirectory)$(ConfigurationLocation) -SubscriptionId $(SubscriptionId) -DevTestLabName $(devTestLabName) -ImagesToSave $(ImageRetention)`
49+
:::image type="content" source="./media/set-retention-policy-cleanup/retire-old-image-task.png" alt-text="Screenshot that shows the details for the Retire images PowerShell task." lightbox="./media/set-retention-policy-cleanup/retire-old-image-task.png":::
4950

50-
## Queue the build
51-
Now that you completed the build definition, queue up a new build to make sure everything is working. After the build completes successfully, the new custom images show up in the destination lab. If you check the image factory lab, you see no provisioned VMs. If you queue up further builds, you see the cleanup tasks retiring old custom images from the DevTest Labs. The retirement accords with the retention value set in the build variables.
51+
The script parameters are:
52+
`-ConfigurationLocation $(System.DefaultWorkingDirectory)$(ConfigurationLocation) -SubscriptionId $(SubscriptionId) -DevTestLabName $(devTestLabName) -ImagesToSave $(ImageRetention)`
5253

53-
> [!NOTE]
54-
> If you executed the build pipeline at the end of the last article in the series, manually delete the virtual machines that you created in the image factory lab before queuing a new build. You only need the manual cleanup step while you set everything up and verify it works.
54+
## Queue the build
5555

56+
After you complete the build definition, queue up a new build to make sure everything is working. After the build completes successfully, the new custom images show up in the destination lab. If you check the image factory lab, you see no provisioned VMs. If you queue up further builds, you see the cleanup tasks retiring old custom images from the DevTest labs. The retirement proceeds according to the retention value set in the build variables.
5657

58+
> [!NOTE]
59+
> If you ran the build pipeline at the end of the previous article in this series, manually delete the virtual machines that you created in the image factory lab before queuing a new build. You only need the manual cleanup step when you set everything up and verify that it works.
5760
5861
## Summary
59-
Now you have a running image factory that can generate and distribute custom images to your labs on demand. At this point, it's just a matter of getting your images set up properly and identifying the target labs. As mentioned in the previous article, the **Labs.json** file located in your **Configuration** folder specifies which images should be made available in each of the target labs. As you add other DevTest Labs to your organization, you simply need to add an entry in the Labs.json for the new lab.
6062

61-
Adding a new image to your factory is also simple. When you want to include a new image in your factory, open the [Azure portal](https://portal.azure.com) and navigate to your factory lab. Select the button to add a VM, and choose the marketplace image and artifacts you want. Instead of selecting the **Create** button to make the new VM, select **View Azure Resource Manager template**. Save the template as a .json file somewhere within the **GoldenImages** folder in your repository. The next time you run your image factory, it will create your custom image.
63+
You now have a running image factory that can generate custom images and distribute them to your labs on demand. At this point, it's just a matter of getting your images set up properly and identifying the target labs. As mentioned in the previous article, the *Labs.json* file located in your *Configuration* folder specifies which images should be made available in each of the target labs. As you add other DevTest labs to your organization, you simply need to add an entry in *Labs.json* for the new lab.
6264

65+
Adding a new image to your factory is also easy. When you want to include a new image in your factory, go to your factory lab in the Azure portal. Select the button to add a VM, and then choose the marketplace image and artifacts that you want. Instead of selecting the **Create** button to create the new VM, select **View Azure Resource Manager template**. Save the template as a .json file somewhere in the *GoldenImages* folder in your repository. The next time you run your image factory, it will create your custom image.
6366

6467
## Next steps
65-
1. [Schedule your build/release](/azure/devops/pipelines/build/triggers?tabs=designer) to run the image factory periodically. It refreshes your factory-generated images regularly.
66-
2. Make more golden images for your factory. You may also consider [creating artifacts](devtest-lab-artifact-author.md) to script more pieces of your VM setup tasks and include the artifacts in your factory images.
67-
4. Create a [separate build/release](/azure/devops/pipelines/overview) to run the **DistributeImages** script separately. You can run this script when you make changes to Labs.json and get images copied to target labs without having to recreate all the images again.
68+
69+
- [Schedule your build/release](/azure/devops/pipelines/build/triggers?tabs=designer) to run the image factory periodically. It refreshes your factory-generated images regularly.
70+
- Make more golden images for your factory. Consider [creating artifacts](devtest-lab-artifact-author.md) to script more pieces of your VM setup tasks and include the artifacts in your factory images.
71+
- Create a [separate build/release](/azure/devops/pipelines/overview) to run the *DistributeImages* script separately. You can run this script when you make changes to *Labs.json* and get images copied to target labs without having to re-create all the images.

0 commit comments

Comments
 (0)