Does Capistrano provide a variable that contains the number of previous deployments?
Yes, releases.length
Is there a way for a pimp to deploy: cleanup, so it uses a minimum threshold?
Yes, here is a special task with names that will run the usual cleaning task ONLY if a certain number of folders for release have been created:
namespace :mystuff do task :mycleanup, :except => { :no_release => true } do thresh = fetch(:cleanup_threshold, 70).to_i if releases.length > thresh logger.info "Threshold of #{thresh} releases reached, runing deploy:cleanup." deploy.cleanup end end end
To run this run automatically after deployment, put this at the top of the recipe:
after "deploy", "mystuff:mycleanup"
Itβs good that the before and after directives installed on deploy:cleanup are executed as usual. For example, we require the following:
before 'deploy:cleanup', 'mystuff:prepare_cleanup_permissions' after 'deploy:cleanup', 'mystuff:restore_cleanup_permissions'
source share