Jenkins Scriptler in 90mins

9,351 views

Published on

Learn Jenkins Scriptler in 90 minutes

Published in: Technology

Jenkins Scriptler in 90mins

  1. 1. Larry cai <larry.caiyu@gmail.com>
  2. 2. Agenda        What is Jenkins Scriptler ? Exercise 1: Hello World in Jenkins script console Exercise 2: Hook into Jenkins Exercise 3: Jenkins Java API Exercise 4: Find the needed Jenkins Java method Exercise 5: Put into Jenkins Scriptler Exercise 6: Learn more Groovy 2 Jenkins Scriptler in 90 minutes
  3. 3. Jenkins Scriptler    Administering your jenkins scripts, which is used to trouble-shooting and diagnostics or routing tasks in jenkins Provides a way to share scripts between users via hosted script catalogs on the internet. Install plugin https://wiki.jenkins-ci.org/display/JENKINS/Scriptler+Plugin  Use http://<jenkins job>/scriptler/ or Jenkins -> Scriptler (system menu) 3 Jenkins Scriptler in 90 minutes
  4. 4. Jenkins script    Jenkins script can access to Jenkins instance data and manipulate directly Jenkins script use Groovy, which is an agile and dynamic language for the Java Virtual Machine a.k.a java-like script language over JVM 4 Jenkins Scriptler in 90 minutes
  5. 5. Exercise 1 – Hello World  Jenkins Console the place to exercise the Jenkins script https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console 5 Jenkins Scriptler in 90 minutes
  6. 6. Exercise 2 – Hook into Jenkins    Get the jenkins java instance ji = jenkins.model.Jenkins.instance All the items (include jobs) jobs = ji.items Printout the job names started with “test” 6 Jenkins Scriptler in 90 minutes
  7. 7. Exercise 3: Jenkins Java API    Script use jenkins JAVA API to access internal data http://javadoc.jenkins-ci.org/ Jenkins instance is http://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html Then locate “getAllItems()” API 7 Jenkins Scriptler in 90 minutes
  8. 8. Exercise 4 – Find the needed method  Find the Item API and try to printout the url for the jobs  If needed, check the source code if java developers https://github.com/jenkinsci/jenkins/blob/master/core/src/main/ Otherwise Check samples ;-)  8 Jenkins Scriptler in 90 minutes
  9. 9. Exercise 5: Put into Jenkins Scriptler  Now put the scripts into Jenkins Scriptler Id & Name: geturl  Add parameter for “job_prefix”, use “$name”  9 Jenkins Scriptler in 90 minutes
  10. 10. Exercise 6: learn more Groovy    Install Groovy Console http://groovy.codehaus.org/ Learn loop syntax http://groovy.codehaus.org/Looping List string in closures way 10 Jenkins Scriptler in 90 minutes
  11. 11. Reference  Market place    Groovy   http://scriptlerweb.appspot.com/catalog/list https://github.com/jenkinsci/jenkins-scripts/tree/master/scriptler http://groovy.codehaus.org Small guideline  11 http://earlyandoften.wordpress.com/2013/03/11/masteringjenkins-making-bulk-updates-to-jobs/ Jenkins Scriptler in 90 minutes

×