Skip to content
Snippets Groups Projects

Remove all job logs and artifacts in GitLab

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Erik Hedenström

    Use with caution. This is a gitlab-rails console script that removes all job logs and artifacts. Good for small test instances when you need to free up some space.

    prune-builds.rb 272 B
    admin_user = User.find_by(username: 'root')
     Ci::Build.find_each do |build|
       print "Ci::Build ID #{build.id}… "
       if build.erasable?
         build.erase(erased_by: admin_user)
         puts "Erased"
       else
         puts "Skipped (Nothing to erase or not erasable)"
       end
     end
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment