using groovy with jenkins

36
1

Upload: saschaklein

Post on 13-Apr-2017

704 views

Category:

Software


3 download

TRANSCRIPT

Page 1: Using Groovy with Jenkins

1

Page 3: Using Groovy with Jenkins

3

Page 4: Using Groovy with Jenkins

4

Page 5: Using Groovy with Jenkins

Jenkins.instance.doQuietDown()

Jenkins.instance.numExecutors=5Jenkins.instance.slaveAgentPort=[55000]

defglobal_domain=Domain.global()defcredentials_store=Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].storedefcredentials=newBasicSSHUserPrivateKey(CredentialsScope.GLOBAL,null,"root",newBasicSSHUserPrivateKey.UsersPrivateKeySource(),"","")credentials_store.addCredentials(global_domain,credentials)

5

Page 6: Using Groovy with Jenkins

java-jarjenkins-cli.jar[-sJENKINS_URL]command[options… ][arguments… ]

java-jarjenkins-cli.jar-s groovysomescript.groovy

java-jarjenkins-cli.jar-s groovysh

http://jenkins

http://jenkins

6

Page 7: Using Groovy with Jenkins

importhudson.plugins.chucknorris.CordellWalkerRecorderfor(iteminJenkins.instance.items){item.publishersList.replace(newCordellWalkerRecorder())}

disableChildren(Hudson.instance.items)defdisableChildren(items){for(iteminitems){if(item.class.canonicalName!='com.cloudbees.hudson.plugins.folder.Folder'){ if(m=item.name=~/^(Hudson_)(\..*)$/)item.renameTo('Jenkins_'+m.group(2))}elsedisableChildren(item.items)}}

7

Page 8: Using Groovy with Jenkins

$curl--data-urlencode"script=$(<./somescript.groovy)"

$curl--user'username:password'...

http://jenkins/scriptText

8

Page 10: Using Groovy with Jenkins

10

Page 12: Using Groovy with Jenkins

12

Page 13: Using Groovy with Jenkins

13

Page 14: Using Groovy with Jenkins

14

Page 15: Using Groovy with Jenkins

15

Page 17: Using Groovy with Jenkins

17

Page 18: Using Groovy with Jenkins

node{//Markthecodecheckout'stage'....stage'Checkout'//GetsomecodefromaGitHubrepositorygiturl:'https://github.com/jglick/simple-maven-project-with-tests.git'//Getthemaventool.//This'M3'maventoolmustbeconfiguredintheglobalconfigurationdefmvnHome=tool'M3'stage'Build'//Runthemavenbuildsh"${mvnHome}/bin/mvncleaninstall"}

18

Page 20: Using Groovy with Jenkins

20

Page 21: Using Groovy with Jenkins

defproject='quidryan/aws-sdk-test'defbranchApi=newURL("https://api.github.com/repos/${project}/branches")defbranches=newgroovy.json.JsonSlurper().parse(branchApi.newReader())branches.each{defbranchName=it.namedefjobName="${project}-${branchName}".replaceAll('/','-')job(jobName){scm{git("git://github.com/${project}.git",branchName)}steps{maven("test-Dproject.name=${project}/${branchName}")}}}

21

Page 22: Using Groovy with Jenkins

22

Page 23: Using Groovy with Jenkins

deflabelMap=[arm:"armcc",win:"vs2010",linux:"gcc"]returnlabelMap."${binding.variables.platform}"

23

Page 24: Using Groovy with Jenkins

24

Page 26: Using Groovy with Jenkins

▸ ▸

26

Page 28: Using Groovy with Jenkins

▸ ▸

28

Page 29: Using Groovy with Jenkins

29

Page 30: Using Groovy with Jenkins

importgroovyx.remote.client.RemoteControlimportgroovyx.remote.transport.http.HttpTransportdeftransport=newHttpTransport("http://myJenkins/plugin/groovy-remote")defremote=newRemoteControl(transport)

//Thiscoderunsonlocal.defname='kiy0taka'printlnname

defresult=remote{//ThisclosurerunsonJenkinsserver.defversion=jenkins.version.valueprintln"Hi,${name}!"

//ReturnJenkinsversion.returnversion}

//Thiscoderunsonlocal.println"Jenkinsversionwas${result}."

30

Page 32: Using Groovy with Jenkins

▸ ▸

32

Page 33: Using Groovy with Jenkins

33

Page 34: Using Groovy with Jenkins

defauthors="[hiddenemail]"

if(build.environment["RELEASE_BUILD"]){authors=build.environment["RELEASE_BUILD_EMAIL_DISTRIBUTION"]}

returnauthors

34

Page 35: Using Groovy with Jenkins

buildresultis${build.result}buildurlis${rooturl}${build.url}<%defchangeSet=build.changeSetif(changeSet!=null){defhadChanges=falsechangeSet.each(){cs-> hadChanges=true defaUser=cs.author%>Revision:(${aUser.displayName})${cs.msgAnnotated}<% cs.affectedFiles.each(){p->%>${p.editType.name},${p.path}<%}}if(!hadChanges){%>NoChanges<%}}%>

35