We have our code deployment to AEM servers using curl command through CI-CD pipelines. While the number of deployments (packages being deployed) per day is more compared to UAT and Prod, we now have a huge amount of redundant old packages lying which is taking more disk space and slowing the performance of AEM especially Package manager screen. Is there a way to delete old packages during new code deployment (through curl or any other means) or a maintenance task or programatic way to delete these old packages?
If you delete a a package, there are various problems/inconsistencies that may come up. 1. If you have subpackages, they won't get deleted. eg. adobe core components package 2. If you have bundles, they won't get deleted.
So ideally you should include the uninstall the package. This step as the first step in your deployment process. 1. if you have a blue green deployment strategy, you can uninstall until the latest version. 2. If not, you can think of the below process with a rule to uninstall until n-1 version.
For uninstall, there is no straight away API to consume, but the best way is
1. Fetch the list of packages /crx/packmgr/list.jsp using curl
2. Parse the results with any identifier like package name in the pipeline