You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/devtest-labs/image-factory-set-retention-policy-cleanup.md
+37-33Lines changed: 37 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,63 +6,67 @@ ms.author: rosemalcolm
6
6
author: RoseHJM
7
7
ms.date: 07/21/2025
8
8
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.
9
11
---
10
12
11
13
# Set up an image retention policy in Azure DevTest Labs
12
14
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.
17
16
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
21
18
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)
23
28
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
-
30
29
## 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.
32
30
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
35
34
36
-

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:
37
36
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":::
39
38
40
-

39
+
After you have the new task in the list, select the item, and then provide the details shown here:
41
40
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)`
43
45
44
46
## 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:
46
47
47
-

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:
:::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":::
50
51
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.
> 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
56
56
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.
57
58
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.
58
61
59
62
## 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.
61
63
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.
63
65
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.
64
67
65
68
## 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