In our staging environment, we are having a lot of deployments from different branches into our test Kubernetes Cluster via Gitlab.
So, a project with 3 different feature branches, and a bug fix branch has their own isolated deployments.
Once they are merged back to release branch, I am seeking a wise way to delete all obsolete 4 branches (k8s deployments), because we do not need them anymore.
As a first approach, once merge happens, I will be triggering a delete deployment command for merged branch.
feature112 -> git merge -> release -> k8s delete deployment feature112
But not all branches will be merged. Feature can be cancelled, or bugfix is not a real bug.
For those scenarios I am thinking to have a background job to check if a project other than release has a deployment more than 2 days then I will delete them. Then dev needs to re-deploy it if needed.
For example, deployments are:
myapp-release (stays forever)
myapp-feature-123 (deployed 23 hours ago - stay)
myapp-bugfix-124 (deployed 64 hours ago - delete)
Therefore I am trying to not to host historical branches and bugfixes.
AFAIK gitlab does not support delete branch triggers.
https://gitlab.com/gitlab-org/gitlab-ce/issues/54216
What would be the best approach to take on this problem?