-
Notifications
You must be signed in to change notification settings - Fork 444
The CI environment Deployment history cleanup
This pipeline and its scripts can be used to limit the number of deployments that are listed in Azure at any given time. This is especially useful for a scope like 'Management Group' is Azure does not provide any automatic cleanup.
The corresponding error message would look similar to Creating the deployment '<deploymentName>' would exceed the quota of '800'. The current deployment count is '804'. Please delete some deployments before creating a new one, or see https://aka.ms/800LimitFix for information on managing deployment limits.
The platform pipeline platform.deployment.removal.yml has an automatic schedule that runs every night, but can also be triggered on-demand.
By default, the pipeline will cleanup both the Subscription, as well as Management Group scope using the used script's default configuration. In addition, you can specify a pipeline variable maxDeploymentRetentionInDays to define beyond which time frame deployments should always be deleted. Within the timeframe, only non-failed and non-running deployments are considered.
NOTE
In order for the pipeline to remove both Management-Group-Level as well as Subscription-Level deployments the used service principal needs the permissions either scope. If you use CARML to test deployments on any of these scopes your principal will already have the required permissions.
In case the principal does not have the required permissions you can either:
- Not register the
platform.deployment.removal.ymlpipeline OR- Adjust the pipeline's default behavior to not remove deployments on the scope you'd like to preserve (i.e., change
default: truetodefault: false)
You can find the used scripts under
-
/utilities/pipelines/deploymentRemoval/Clear-SubscriptionDeploymentand /utilities/pipelines/deploymentRemoval/Clear-ManagementGroupDeployment
Both scripts work in the same way:
- The script fetches all current deployments at a given scope from Azure (i.e., Management-Group-scope or Subscription-scope).
- For example, it may find
- 120 successful deployments
- 10 failed deployments that are 3 weeks old
- 10 failed deployments that are 1 week old
- 10 running
- For example, it may find
- By default it then filters them down to non-running & non-failing deployments (can be modified). It only considers failed deployments if they are older than a provided time limit in which case they are included too.
- Following the example, and with a time limit of 2 weeks, it now only considers the
- 120 successful deployments
- 10 failed deployments that are 3 weeks old
- Following the example, and with a time limit of 2 weeks, it now only considers the
- Lastly, it removes all matching deployments in chunks of 100 deployments each.
- In context of the example, this mean it deletes the deployments with to commands, first removing 100, and then 30 deployments.
For details on how to use the functions, please refer to the scripts local documentation.
Note: Each script must be loaded ('dot-sourced') before the function can be invoked.