What ho lads!
Few days ago I was talking with Olivier Renault [1] about few things that he needs to deploy JinFeng [1] using a non-interactive command line. JinFeng is an integration and testing platform built on top of many Open Source tools, like TestLink [2] and Jenkins [3]. One of the features he needs is Test Steps in TestLink XML-RPC API (I’m working on this, and hopefully will be able to provide a patch for TestLink 1.9.4).
The command to install plug-ins is quite simple and intuitive.
java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin testlink
Jenkins CLI has some built-in commands, like install-plugin. But it doesn’t have a built-in command to check if a plug-in is already installed. So a workaround is to use the groovy command, that executes Groovy scripts in Jenkins (you may find convenient to use the groovysh command too, to execute your Groovy scripts, or http://localhost:8080/script for a web Groovy console).
Here is a sample script that checks if a plug-in is already installed or not.
[gist][/gist]
Now you can execute this script as following: cat ~/script1.groovy | java -jar jenkins-cli.jar -s http://localhost:8080 groovy =
It will output 1 if Jenkins has the plug-in installed, or 0 otherwise.
[gist][/gist]
You may be wondering how I’m creating these scripts. I’ll blog about that later. But here’s a quick explanation. I checked out Jenkins sources from GitHub, then imported the project in Eclipse. Then I create an empty class there, with a main method. Finally, I write what I would like to have in a Groovy script, but in Java. The last step is just convert it to Groovy, and voilĂ !
Hope it helps other people too. If you use many scripts for administering Jenkins, you may be interested in Scriptler plug-in [5] too. They even have a scripts repository. Awesome, no? You can download the scripts mentioned in this post from there too. I simply love Jenkins community.
Cheers
[1] http://www.sqaopen.net/ [2] http://www.teamst.org [3] http://www.jenkins-ci.org [4] https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI [5] http://wiki.hudson-ci.org/display/HUDSON/Scriptler+Plugin