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

10

63

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. problem.

How can I solve this problem, it make my master offline for hours?

Mimi answered 26/4, 2012 at 1:13 Comment(2)
How much available disk space was there when you first deployed Jenkins? Perhaps you should host Jenkins on a machine with more available disk space.Mycah
I have 80GB of server and only 2 job and 5 build is there. so i do not think i have less memory. may be jenkins is taking logsDuad
G
41

You can easily change the threshold from jenkins UI (my version is 1.651.3):

[jenkins nodes preventing monitoring page]


Update: How to ensure high disk space

This feature is meant to prevent working on slaves with low free disk space. Lowering the threshold would not solve the fact that some jobs do not properly cleanup after they finish.

Depending on what you're building:

  1. Make sure you understand what is the disk output of your build - if possible - restrict the output to happen only to the job workspace. Use workspace cleanup plugin to cleanup the workspace as post build step.
  2. If the process must write some data to external folders - clean them up manually on post build steps.

Alternative1 - provision a new slave per job (use spot slaves - there are many plugins that integrate with different cloud provider to provision on the fly machines on demand)

Alternative2 - run the build inside a container. Everything will be discarded once the build is finished

Gamine answered 22/12, 2016 at 12:42 Comment(5)
Ah I was looking at [node name] > configure. You described nodes > configure. nvm imgur.com/a/CeTcAConciliar
This shouldn't be the answer though surely? This doesn't fix the low disk space issue. It just hides the warning from Node Monitoring?Sliding
@TryingToLearnJS I actually agree (and I wrote this answer) - It depends what is the question - if someones wants to keep working on slave with < 1GB - it answers how to configure it on Jenkins. If someone needs some automatic cleanup methodology it doesn't. But the latter depends very much on what you are running on Jenkins.Gamine
but thanks on your feedback - I added a generic section that might answer both concernsGamine
@Gamine thanks man! Changing the threshold did help me. Since the nodes go offline when dropping below so changing that allowed me to bring them back up and fix some stuff. And thanks for the updated answer :)Sliding
T
29

Beside above solutions, there is a more "COMMON" way - directly delete the largest space consumer from Linux machine. You can follow the below steps:

  1. Login to Jenkins machine (Putty)
  2. cd to the Jenkins installation path

Using ls -lart to list out hidden folder also, normally jenkin installation is placed in .jenkins/ folder

[xxxxx ~]$ ls -lart

drwxrwxr-x 12 xxxx 4096 Feb 8 02:08 .jenkins/

  1. list out the folders spaces

Use df -h to show Disk space in high level

du -sh ./*/ to list out total memory for each subfolder in current path.

du -a /etc/ | sort -n -r | head -n 10 will list top 10 directories eating disk space in /etc/

  1. Delete old build or other large size folder

enter image description here

Normally ./job/ folder or ./workspace/ folder can be the largest folder. Please go inside and delete base on you need (DO NOT delete entire folder).

rm -rf theFolderToDelete

Tyche answered 14/2, 2017 at 7:22 Comment(0)
B
10

You can limit the reduce of disc space by discarding the old builds. There's a checkbox for this in the project configuration.

Bad answered 17/5, 2012 at 22:16 Comment(1)
The builds information is saved on the master server. This kind of issue is mostly happen at the salve side, where each job has a workspace contains the source code and build results.Sully
T
4

I got the same issue. My jenkins version is 2.3 and its UI is slightly different. Putting it here so that it may helps someone. Increasing both disk space thresholds to 5GB fixed the issue.

enter image description here

Tedra answered 25/7, 2018 at 5:15 Comment(0)
P
3

This is actually a legitimate question so I don't understand the downvotes, perhaps it belongs on Superuser or Serverfault. This is a soft warning threshold not hard limit where the disk is out of space.

Jenkins is the same. The conclusion is for many small projects the system property called hudson.diagnosis.HudsonHomeDiskUsageChecker.freeSpaceThreshold could be decreased.

In saying that I haven't tested it and there is a disclaimer

No compatibility guarantee

In general, these switches are often experimental in nature, and subject to change without notice. If you find some of those useful, please file a ticket to promote it to the official feature.

Pickmeup answered 26/6, 2012 at 4:9 Comment(2)
So set thresholds is to prevent node going down due to out of space? This doesn't help. We are constantly having out of space issue on the slave server due to large number of projects. What's the best solution to fix this issue?Sully
Add another slave, install more disk space, or more likely you need to get jobs to clean up their workspace when complete. You might find there are unnecessary and unexpectedly large files lying around superuser.com/q/9847/81584Pickmeup
S
3

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 /
Struma answered 12/3, 2020 at 7:4 Comment(0)
L
1

To check the free space as Jenkins Job:

Parameters

  • FREE_SPACE: Needed free space in GB.

Job

#!/usr/bin/env bash

free_space="$(df -Ph . | awk 'NR==2 {print $4}')"

if [[ "${free_space}" = *G* ]]; then
  free_space_gb=${x/[^0-9]*/}

  if [[ ${free_space_gb} -lt ${FREE_SPACE} ]]; then
    echo "Warning! Low space: ${free_space}"
    exit 2
  fi
else
  echo "Warning! Unknown: ${free_space}"
  exit 1
fi


echo "Free space: ${free_space}"

Plugins

Set build description

Post-Build Actions

  • Regular expression: Free space: (.*)
  • Description: Free space: \1

  • Regular expression for failed builds: Warning! (.*)

  • Description for failed builds: \1
Luau answered 6/10, 2019 at 15:57 Comment(0)
S
1

For people who do not know where the configs are, download the tmpcleaner from https://updates.jenkins-ci.org/download/plugins/tmpcleaner/

You will get an hpi file here. Go to Manage Jenkins-> Manage plugins-> Advanced and then upload the hpi file here and restart jenkins

You can immediately see a difference if you go to Manage Nodes.

Since my jenkins was installed in a debian server, I did not understand most of the answers related to this since i cannot find a /etc/default folder or jenkins file. If someone knows where the /tmp folder is or how to configure it for debian , do let me know in comments

enter image description here

Spacious answered 18/1, 2021 at 11:54 Comment(0)
B
0

with version 2.401.3

-> Manage Jenkins --> Nodes --> Nodes Monitoring. & change the disk threshold for /tmp directory. you can also set the threshold value for "/".

enter image description here

Bogus answered 17/8, 2023 at 11:23 Comment(0)
H
0

In my case i'm using Windows as a slave machine and the tmp space is refering to C-Drive.

Helix answered 7/6 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.