How to solve jenkins 'Disk space is too low' issue?

前端 未结 8 1395
南笙
南笙 2021-01-31 07:40

I have deployed Jenkins in my CentOS machine, Jenkins was working well for 3 days, but yesterday there was a Disk space is too low. Only 1.019GB left.

8条回答
  •  渐次进展
    2021-01-31 08:22

    I have a cleanup job with the following build steps. You can schedule it @daily or @weekly.

    1. Execute system groovy script build step to clean up old jobs:
        import jenkins.model.Jenkins
        import hudson.model.Job
    
        BUILDS_TO_KEEP = 5
    
        for (job in Jenkins.instance.items) {
          println job.name
    
          def recent = job.builds.limit(BUILDS_TO_KEEP)
    
          for (build in job.builds) {
            if (!recent.contains(build)) {
              println "Preparing to delete: " + build
              build.delete()
            }
          }
        }
    

    You'd need to have Groovy plugin installed.

    1. Execute shell build step to clean cache directories
    rm -r ~/.gradle/
    rm -r ~/.m2/
    
    echo "Disk space"
    du -h -s /
    

提交回复
热议问题