How to delete CI/CD job.log from gitlab

Today I find that one of my project consume more than 80G Project Storage, at first, I thought the project history consume this space, but…

How to delete CI/CD job.log from gitlab

Today I find that one of my project consume more than 80G Project Storage, at first, I thought the project history consume this space, but when I navigate to the detail page from Project Storage page, I find that Job artifacts spend most of the space, this is how to delete the job.log files from gitlab instance.

Delete old files

sudo find /var/opt/gitlab/gitlab-rails/shared/artifacts -name "job.log" -mtime +30 -delete

Delete references to missing artifacts

sudo gitlab-rails console 
 
# Run the following command in the console 
artifacts_deleted = 0 
::Ci::JobArtifact.find_each do |artifact|                      ### Iterate artifacts 
  next if artifact.file.filename != "job.log"                 ### Uncomment if only `job.log` files' references are to be processed 
  next if artifact.file.file.exists?                           ### Skip if the file reference is valid 
  artifacts_deleted += 1 
  puts "#{artifact.id}  #{artifact.file.path} is missing."     ### Allow verification before destroy 
  artifact.destroy!                                           ### Uncomment to actually destroy 
end 
puts "Count of identified/destroyed invalid references: #{artifacts_deleted}"

References

How to remove job logs

Delete references to missing artifacts