Last active
April 8, 2020 19:03
-
-
Save abihf/223f5c0d67bac04d34a2875cffcca07e to your computer and use it in GitHub Desktop.
Clean jenkins jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Jenkins.instance.slaves.each { | |
def comp = it.getComputer() | |
if (comp.isOffline()) { | |
comp.doDoDelete() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
find /var/jenkins_home/jobs -name build.xml | grep -v "/release/" | while read file ; do | |
dir_name="$(dirname "${file}")" | |
mtime=$(stat -c '%Y' "${file}") | |
now=$(date +%s) | |
age=$(( ( now - mtime ) / 86400 )) | |
if [ $age -gt 14 ]; then | |
echo Deleting ${age} old days ${dir_name} | |
rm -r "${dir_name}" | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def now = new Date() // Get the current time | |
// Get a list of all running jobs | |
def buildingJobs = Jenkins.instance.getAllItems(Job.class).findAll{ it.isBuilding() }.each { job-> | |
// Enumerate all runs | |
job._getRuns().each { item -> | |
// If NOT currently building... check the next build for this job | |
if (!item.isBuilding()) return | |
// Access and calculate time information for this build. | |
def startedAt = new Date(item.getStartTimeInMillis()) | |
def duration_mins = ((now.getTime() - item.getStartTimeInMillis()) / 60000).intValue() | |
println("${duration_mins}: ${item.getUrl()}") | |
if (duration_mins > 60) { | |
item.doKill() | |
} | |
} | |
} | |
[] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment