Tuesday, April 22, 2014

How to delete a set of old builds in Jenkins? Using CLI

You can use Jenkins command-line-interface(CLI) to delete some old build numbers. To run jenkins CLI, you need java and jenkins-cli.jar.

Where is jenkins-cli.jar?
In the machine where jenkins is hosted, you can find jenkins.war. Extract it using the command 'jar -xvf ../jenkins.war'. You can find it under WEB-INF/jenkins-cli.jar.

What is the command to delete jenkins jobs?
java -jar jenkins-cli.jar -s http://ci.jenkins-ci.org/ delete-builds JOB RANGE

where
JOB   : Name of the job to build
RANGE : Range of the build records to delete. 'N-M', 'N,M', or 'N'

Example:

java -jar WEB-INF/jenkins-cli.jar -s https://emc-jenkins:8443/jenkins delete-builds DLP-EM-9.6-SP2-HF1-Daily '22176-22190' --username guruss1
Failed to authenticate with your SSH keys.
Password:

Deleted 15 builds

It deleted build numbers from 22176 to 22190.