Post

Automating shelving of Jenkins jobs

2 tags

The current version of the shelve plugin does not support shelving multiple projects. Luckily, it is possible using a simple bash script.

The current version of the shelve plugin does not support shelving multiple projects. This can be a pain if you have a large Jenkins deployment. Luckily, it is possible to shelve multiple projects using a simple bash script.

If you have the jenkis-cli jar on your system, this can be can in two steps:

  1. First generate a list of jobs to shelve:
java -jar jenkins-cli.jar -noCertificateCheck -http -user <your user> -i <key> -s http://jenkins.host.com:8080/ list-jobs | grep jobs-I-want-to-remove > ~/tmp/shelve-list.txt
  1. Iterate over the list to shelve the projects:
i=0 ; for job in $(cat ~/tmp/shelve-list.txt) ; do curl -u <user>:<password> -X POST -D "{}" http://jenkins.host.com:8080/job/$job/shelve/shelveProject ; ((i++)) ; [[ $i == 10 ]] && echo "Waiting ... " && sleep 10 && export i=0; done

This script uses a small delay between every couple shelve requests. This is useful if your jobs contain a lot of data and Jenkins will take too long to shelve them.