Prerequisites
You need to have a java installation on your machine and java must be available on your PATH. groovy itself is not required to execute the scripts.
I assume that you have Jenkins running on your machine, so that I refer to localhost to access the Jenkins instance.
- If you already have a copy of jenkins-cli.jar on your machine, then skip to step 2. Otherwise open a browser and navigate to this URL http://localhost:8080/cli. Follow the instructions and download the jenkins-cli.jar to a known directory
- Open a terminal or command window and change into the directory where your jenkins-cli.jar is located
- Type java -jar jenkins-cli.jar -s http://localhost:8080 help. This will output a list of all available commands that this jenkins instance provides.
- Okay, now go ahead and save this snippet as listAllProjectsWithPerforceSCM.groovy to the same directory where you previously downloaded the jenkins-cli.jar
- Now enter the following on the command line:
java -jar jenkins-cli.jar -s http://localhost:8080 groovy listAllProjectsWithPerforceSCM.groovy
Job 'Test' uses the following perforce configuration
------------------------------------------------------------------------
P4Port: localhost:1666
P4Client: testbuilder
P4User: testbuilder
P4Password: 0f0kqlwaDeXrEj0PA0z/+IXZM1f8G8QsgBlUgnUv8bbR2bzXLfa3AlrK8xqw==
That's it. There is nothing complicated about this script, but it shows some of the capabilities to automate certain tasks. Take the script as example to play around with it and explore new ways to interact with jenkins.
Thanks for reading this post.
3 comments:
Thank you for the information, but I do have a question. Hudson and the hudson cli are installed as well as groovy (I have run cli and groovy commands from a terminal) but I am getting syntax errors. I am new to groovy, so it's likely an error on my part.
The interpreter complains on the very first line: "No such property: hudson for class: listjobs" where listjobs.groovy is the name of my script.
Thank you in advance for any help!
Mike L.
I'm sorry to hear that it's not working for you.
First of all, you don't need groovy to execute groovy scripts in the jenkins cli, since groovy is part of jenkins.
Are you using Jenkins or Hudson? I used Jenkins for this example and I never tried Hudson.
Can you send me your groovy script? I'm going to have a look at it.
Thanks,
Ingo
Post a Comment