Skip to content

Commit 872d3b2

Browse files
committed
updates
1 parent a37c5c5 commit 872d3b2

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

articles/devtest-labs/image-factory-set-retention-policy-cleanup.md

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,67 @@ ms.author: rosemalcolm
66
author: RoseHJM
77
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

1113
# Set up an image retention policy in Azure DevTest Labs
1214

13-
This article covers setting a retention policy, cleaning up the factory, and retiring old images from all the other DevTest Labs in the organization.
14-
15-
## Prerequisites
16-
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.
1716

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

22-
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+
- A build definition to orchestrate the Azure PowerShell tasks.
24+
- Completion of the steps in these articles:
25+
- [Create an image factory](image-factory-create.md)
26+
- [Run an image factory from Azure DevOps](image-factory-set-up-devops-lab.md)
27+
- [Save custom images and distribute to multiple labs](image-factory-save-distribute-custom-images.md)
2328

24-
- A lab for the image factory in Azure DevTest Labs
25-
- One or more target Azure DevTest Labs where the factory will distribute golden images
26-
- An Azure DevOps Project used to automate the image factory.
27-
- Source code location containing the scripts and configuration (in our example, in the same DevOps Project used above)
28-
- A build definition to orchestrate the Azure PowerShell tasks
29-
3029
## Setting the retention policy
31-
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.
3230

33-
## Cleaning Up the factory
34-
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:
31+
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.
32+
33+
## Cleaning up a factory
3534

36-
![Screenshot that shows a PowerShell step.](./media/set-retention-policy-cleanup/powershell-step.png)
35+
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:
3736

38-
Once you have the new task in the list, select the item, and fill in all the details as shown in the following image:
37+
:::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":::
3938

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

42-
The script parameters are: `-DevTestLabName $(devTestLabName)`.
41+
:::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":::
42+
43+
The script parameters are:
44+
`-DevTestLabName $(devTestLabName)`
4345

4446
## Retire old images
45-
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:
4647

47-
![Screenshot that shows Retire old images PowerShell task.](./media/set-retention-policy-cleanup/retire-old-image-task.png)
48+
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:
4849

49-
The script parameters are: `-ConfigurationLocation $(System.DefaultWorkingDirectory)$(ConfigurationLocation) -SubscriptionId $(SubscriptionId) -DevTestLabName $(devTestLabName) -ImagesToSave $(ImageRetention)`
50+
:::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":::
5051

51-
## Queue the build
52-
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.
52+
The script parameters are:
53+
`-ConfigurationLocation $(System.DefaultWorkingDirectory)$(ConfigurationLocation) -SubscriptionId $(SubscriptionId) -DevTestLabName $(devTestLabName) -ImagesToSave $(ImageRetention)`
5354

54-
> [!NOTE]
55-
> 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.
55+
## Queue the build
5656

57+
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.
5758

59+
> [!NOTE]
60+
> 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.
5861
5962
## Summary
60-
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.
6163

62-
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.
64+
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.
6365

66+
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.
6467

6568
## Next steps
66-
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.
67-
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.
68-
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.
69+
70+
- [Schedule your build/release](/azure/devops/pipelines/build/triggers?tabs=designer) to run the image factory periodically. It refreshes your factory-generated images regularly.
71+
- 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.
72+
- 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)