Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all keep-forever builds in Jenkins?

Is there an easy way in Jenkins to list all all builds marked as keep-forever? And then, ideally, one click to either unmark the build as keep-forever or to immediately delete it?

In our process, we mark a build as keep-forever if it involves some specific type of failure; that's to keep Jenkins from automatically deleting over time. I need an easy way to get a list of all those keep-forever builds so they don't take up all our disk space over time.

like image 606
Jason Swager Avatar asked Mar 08 '12 22:03

Jason Swager


People also ask

Where is Jenkins build history stored?

$JENKINS_HOME is where all Jenkins-based installations store configuration, build logs, and artifacts.

How do you change the number of builds kept by Jenkins?

This is a feature that is given to you by Jenkins so you can change the number of builds you want to keep. If you are using a Declarative pipeline you can just add this to your code: pipeline { options { buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30')) } ... }


2 Answers

The following XPath query against Jenkins will list the URLs of all builds marked 'Keep Forever':

http://[jenkins_server]/api/xml?depth=2&xpath=/hudson/job/build[keepLog="true"]/url&wrapper=forever

Enter it in the browser and see what it returns.

Now, you can embed it into XSLT-based HTML to get a list with links to those builds. To delete the build you can provide a button that invokes Jenkins CLI:

java -jar jenkins-cli.jar -s http://[jenkins_server]/ delete-builds [job-name] [build-num]

Unfortunately, I do not know how to disable 'keep build forever' with CLI without deleting it.

like image 119
malenkiy_scot Avatar answered Nov 10 '22 11:11

malenkiy_scot


I was looking for the same thing, and our jenkins is pretty big as well and trying the link:

 http://[jenkins_server]/api/xml?depth=2&xpath=/hudson/job/build[keepLog="true"]/url&wrapper=forever

I ended up crashing it.

But as it turns out I only require the last 'keep forever' build of one job at a time, which seems to work way faster. So I use the following instead:

http://[jenkisn_server]/job/[job_name]/api/xml/?depth=2&xpath=/freeStyleProject/build[keepLog="true"]/number&wrapper=forever

which returns the xml with all the numbers of build that are marked as 'keep forever' You can modify the xpath to fit your needs.

like image 7
teapothat Avatar answered Nov 10 '22 10:11

teapothat