ï¼2015/05/14 追è¨ï¼ ãã®ã¨ã³ããªã§è¨åãã¦ããSubversionãªãã¸ããªãè¤æ°æå®ã§ããªãåé¡ã§ãããä»ã¯è§£æ±ºããã¦ãã¾ãã
å人ç¨ã¡ã¢ãå ¼ãã¦ã
ã¡ãã£ã¨ãããããã£ãããã¸ã§ã¯ãã§ã¯ãããã¡ã§ãããããç¹å®ã®ç°å¢ã¸ã®ãªãªã¼ã¹ã®ããã«ããã¤ãã®ã¸ã§ãã§æ§æããããã«ããã¤ãã©ã¤ã³ãããããããç°å¢ãã¨ã«å¾®å¦ãªå·®åãã¤ãã¦ãè¤æ°ç¨®é¡ã®ãã«ããã¤ãã©ã¤ã³ãæ§æããå¿ è¦ããã£ãããã¾ãã
ç°å¢ã®æ°ãã¢ããªã®æ°ã«ãã£ã¦ã¯ããããã®å·®åãå«ãã¦Jenkinsä¸ã«ã¸ã§ããæ§æãããã¨ããã¨ãä¸æãããã¨100åè¿ãã¸ã§ãã«å°éãããã¨ãããã¾ãã
ï¼ããã¾ã§ããªãã§ãããããããã¸ã§ãéå¤ãªç¶æ ãé常ã¯ç®æãã¹ãã§ã¯ããã¾ãããï¼
ããããå ´åã«æä½æ¥ã§Jenkinsã®ã¸ã§ããæ§æãããã¨ããã¨æãããã¯ãªãã¯ã²ã¼ã ã«ãªãã®ã§ãJenkinså ¬å¼ãç¨æãã¦ããJob DSL Plugin ã使ã£ã¦ããã°ã©ãã³ã°ã§å¤§éã®ã¸ã§ããå¹çããæ§æãã¾ãããã
Job DSL Pluginã®æ¦è¦
https://github.com/jenkinsci/job-dsl-plugin/wiki
- æ®éã«ãã©ã°ã¤ã³è¨å®ç»é¢ããã¤ã³ã¹ãã¼ã«å¯è½ã§ããå ¥ãã¦ãªã人ã¯ãã²å ¥ãã¾ãããã
- Groovyã®DSLã§ãJenkinsã®ã¸ã§ãããã¥ã¼ããµã¯ãã¨æ§æå¯è½ã
- ç¹°ãè¿ããåå²ãããããªã©Javaï¼Groovyï¼ã«ããéå ·ã使ã£ã¦ã¸ã§ãã®çæãæè»ã«è¡ããã
- åºæ¬çã«DSLã§ã¸ã§ãã»ãã¥ã¼ãã¨ã®è¨å®ãã¡ã¤ã«ï¼XMLï¼ãåºããããªã¤ã¡ã¼ã¸ã
- ä½ã£ãã¸ã§ãã¯ãä½æå¾ãä½æç¨ã®ã¸ã§ãã®ããããã¼ã¸ã«è¡¨ç¤ºããã¾ãã
- ãã§ã«ããã¸ã§ããä½æããå ´åã¯ãè¨å®ãä¸æ¸ããä»ã¾ã§ãã£ãã¸ã§ãã®å±¥æ´ãªã©ã¯ãã¡ãã¨ä¿åããã¾ã
- 以åã«ä½æããããã©ãã次å以éä½æ対象ã«ãªããªãã¸ã§ãï¼è¦ããã«å®ç¾©ãå¤æ´ããã¦æ¶ããã¸ã§ãï¼ã¯ãæ¾ç½®ããããç¡å¹ã«ããããåé¤ãããã¨ãã£ããã¨ãæå®å¯è½ã§ãã
- æå¤ãªã»ã©å¤ç¨®ã®ãã©ã°ã¤ã³ã«å¯¾å¿ãã¦ããã
- ãã®ãã©ã°ã¤ã³ã«DSLãå®ç¾©ããã¦ããJenkinsãã©ã°ã¤ã³ã¯ã¡ã¸ã£ã¼ãªãã©ã°ã¤ã³ã¨æã£ã¦ãããããããã¾ããã
- Job DSL Pluginã対å¿å¤ã®ãã®ã§ãè¨å®ãã¡ã¤ã«ï¼XMLï¼ã»ã¼ãã®ã¾ã¾ã«è¨è¿°ãããã¨ã«ãã対å¿å¯è½ãæä½æ¥ã¸ã§ãè¨å®ä½æ¥ã®å®å ¨ä»£æ¿ã«ã»ã¼ãªãã¯ãã
- ï¼ã¡ãªã¿ã«SCM Sync Pluginã¨ãããä¸ç·ã«ä½¿ãã¨ãå é¨ã®ã¸ã§ãå®ç¾©1ã¤ãã¨ã«SCMã«ã³ãããããã¾ããã¸ã§ãå®ç¾©ããããã³ã«ã³ããããã°ãã¦ã¶ããã¨ã«ãªãã¾ãããæ°ã«ããªããã¨ã«ãã¾ããã:-p ï¼
ãã£ããJob DSLãæ¸ãã¦ã¿ã
ãã¼ã«ã«éçºç°å¢ã®ã¤ã³ã¹ãã¼ã« (Windowså¯)
Jenkinsã®Job DSL Pluginã®Groovyã½ã¼ã¹ã®ããã¹ãã¨ãªã¢ã«DSLãè²¼ãä»ãã¦ãã¸ã§ãã®çæã¯ã§ããã®ã§ããã
- Groovyã®ææ³ãæ£ããã®ãã
- ã»ãã³ãã£ãã¯ãªã¨ã©ã¼ã¯èµ·ããªãã®ãã
- ã©ãããã¸ã§ãå®ç¾©ãåºåãããã®ãã
ãªã©ãªã©Jenkinsä¸ã ãã§å®è¡ãã¿ã³ããããããã¦ãããã確èªããã®ã¯ã¨ã£ã¦ãé¢åãªã®ã§ããã¼ã«ã«ã§DSLã®å®è¡çµæã確èªã§ããç°å¢ãä½ãã¨é常ã«æãã¾ãã
詳ããæé 㯠https://github.com/jenkinsci/job-dsl-plugin/wiki/User-Power-Moves ã«æ¸ãã¦ããã®ã§ãããã¨ããããããã§ãç´¹ä»ãã¦ããã¾ãã
ã¾ãã¯ãGroovyãæ±ããããJDKãå ¥ãã¦ä½¿ããããã«ãã¦ããã¾ãããã
ãã¨ã¯Job DSL Pluginãgit clone
ããããã¦
$> git clone https://github.com/jenkinsci/job-dsl-plugin.git $> cd job-dsl-plugin
ã¡ãã£ã¨é©å½ãªJob DSLãæå®ã®ãã©ã«ãã«ããã¦ããã¾ããããä¸è¨ã®Job DSLãjob-dsl-core/sample.groovy
ã¨ãã¦ä¿åãã¦ãã ããã
def jobNames = ['Alpha', 'Bravo', 'Charlie'] for (jobName in jobNames) { job { name jobName } }
ããã¾ã§ãã£ããä¸è¨ã³ãã³ããå®è¡ããã°ã
./gradlew run -Pargs=sample.groovy
job-dsl-core/
以ä¸ã«ä¸è¨3ã¤ã®ããããã¸ã§ãã®è¨å®ãå
¥ã£ããã¡ã¤ã«ãã§ãã¦ããã¯ãã§ãã
-rw-r--r-- 1 knjname staff 588 Jan 6 01:29 Alpha.xml -rw-r--r-- 1 knjname staff 588 Jan 6 01:29 Bravo.xml -rw-r--r-- 1 knjname staff 588 Jan 6 01:29 Charlie.xml
(Alpha.xmlã®ä¸èº«) <project> <actions></actions> <description></description> <keepDependencies>false</keepDependencies> <properties></properties> <scm class='hudson.scm.NullSCM'></scm> <canRoam>true</canRoam> <disabled>false</disabled> <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> <triggers class='vector'></triggers> <concurrentBuild>false</concurrentBuild> <builders></builders> <publishers></publishers> <buildWrappers></buildWrappers> </project>
åºæ¬çã«ã¯DSLãç·¨éâgradlew run ...
ãå®è¡âãã¼ã«ã«ã«åºåãããXMLã®ä¸èº«ã確èªâDSLãç·¨éãã¨ããã«ã¼ãã§éçºãã¦ãããç´å¾ã§ããå½¢ã«ãªã£ã¦ããæå¾ã«Jenkinsä¸ã§DSLãå®è¡ã¨ããå½¢ã«ãªãã¨æãã¾ãã
Jenkinsä¸ã§Job DSLãåããã¦ã¸ã§ããå®ç¾©ãã
ç¹ã«é£ãããã¨ã¯ãªããTutorialã«ããããã«ãã¸ã§ãçæç¨ã®ç¨®ã¸ã§ããä½æããã ãã§ããã
種ã¸ã§ãã¯é常ã®ã¸ã§ãã¨ã»ã¨ãã©ããããªãã®ã§ããã¨ãã°Job DSLãç¹å®ã®å®ç¾©ãã¡ã¤ã«ãæ´æ°ããããèµ·åããããã«ç¨®ã¸ã§ãã®ããªã¬ããããã¦ããã¦ãç¶æ³ã«å¿ãã¦ã¸ã§ããåæã«å¢ããããã«ãããã¨ãã§ãã¾ãã
ã»ã
åãã©ã°ã¤ã³ã«å¯¾å¿ãããã¥ã¼ãã¸ã§ããããªã¬ã¼ãåå¦çãå¾å¦çãªã©ãªã©ã®æå®æ¹æ³ã¯Wikiãè¦ã¾ãããããªãã¡ã¬ã³ã¹ãå å®ãã¦ãã¾ããæå¤ã«å¯¾å¿ç¯å²ãåºããã¨ã«é©ãã¨æãã¾ãã
Wikiè¦ã¦ãã³ã¨ããªããã°Githubä¸ã§ã½ã¼ã¹ã§è©²å½ã®é¢æ°ãæ¤ç´¢ããã®ãã¦ã£ã¨ãæ©ãã§ãã
èªåã®ä½¿ã£ã¦ãããã©ã°ã¤ã³ã«è©²å½ããDSLããªããã° configure
ãããã¯ãé§ä½¿ãã¦è¨å®ãã¡ã¤ã«ã»ã¼ãã®ã¾ãã¾ã§è¨è¿°ãã¾ãããã
ã¡ãã£ã¨ããTipsãªã©
Gradleã§ã®*.groovyãã¡ã¤ã«ã®æå®æ¹æ³ããã¤ã
å
¥åã¨ãªãDSLã®groovyãã¡ã¤ã«ã絶対ãã¹ã§ç¹å®ã®å ´æã§æå®ããã人ã¯-Pargs=/root/hoge.groovy
(Windowsãªã -Pargs=\C:\Users\root\hoge.groovy
ã¿ããã«æå®)ãè¤æ°æå®ããã人ã¯"-Pargs=hoge.groovy fuga.groovy"
ã¨ããã°å¤§ä¸å¤«ã§ãã
ã¡ãªã¿ã«XMLã®åºåå ´æã®æå®æ¹æ³ã¯ç¥ãã¾ããï¼
Gradleã®èµ·åãé ãã¦ã¤ã©ã¤ã
gradlew
ã®èµ·åãé
ãã¦ã¤ã©ã¤ã©ãã人ã¯gradlew
ã®ã¦ã¼ã¶ãã¨ãããã¡ã¤ã«è¨å®ãã¡ã¤ã«(~/.gradle/gradle.properties
)ã«ä¸è¨ã®å¤ãæå®ãã¦Gradleç¨ã®JVMããã¼ã¢ã³èµ·åãããã¨ããããããï¼
org.gradle.daemon=true
DSLä¸ã§ä½¿ããã³ã³ããã¹ãä¾åã®é¢æ°ã®ä½ãæ¹(ï¼Subversionã®å ´åã®è¤æ°ç®æãã§ãã¯ã¢ã¦ã)
ãã¨ãã°ãSubversionã使ã£ã¦ããå ´åãæ®éã«1ã¸ã§ãå ã§è¤æ°ç®æãããã§ãã¯ã¢ã¦ãããã¨æãã®ã§ãããDSLã§ã¯ãã®æã®ã±ã¼ã¹ã¯æ³å®ããã¦ãã¾ããï¼
ã ããå ¬å¼ã§ã¯ããããã£ã¦ãï¼
scm { svn('http://hoge/svn/trunk', 'hoge') { it / locations << 'hudson.scm.SubversionSCM_-ModuleLocation' { remote 'http://fuga/svn/trunk' local 'fuga' } it / locations << 'hudson.scm.SubversionSCM_-ModuleLocation' { remote 'http://baz/svn/trunk' local 'baz' } } }
ãã±ã¼ã·ã§ã³ã®1åç®ã ããç¹å¥æ±ããã¦æ¸ãã¦ããã¨ã¯ç¡çããè¨å®XMLã¾ãã¾æ¸ãã¨ãã¤ã±ã¦ãªãã§ããã
ãã£ããããã°ã©ãã³ã°è¨èªã使ã£ã¦ããã®ã§ãé¢æ°ã«åºãã¦ãã£ããããã¦ããã¾ãããã
def svnRepositories = { repositories -> svn(repositories[0].remote, repositories[0].local) { if(repositories.size == 1) return for(repos in repositories[1..-1]) { it / locations << 'hudson.scm.SubversionSCM_-ModuleLocation' { remote repos.remote local repos.local } } } } // ... scm { svnRepositories([ [remote: 'http://hoge/svn/trunk', local: 'hoge'], [remote: 'http://fuga/svn/trunk', local: 'fuga'], [remote: 'http://baz/svn/trunk', local: 'baz'], ]) }
Groovyçã«ããã³ã¼ããªã®ãã©ãããããã¾ããããé©å½ã«ä¸è¨ã®ããã«ãã¦ã¿ã¾ããã
ãããããããå®è¡ããã¨ä¸è¨ã®ããã«ä¾å¤ãçºçãã¦ãã¾ãã¾ãã
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: sample.svn() is applicable for argument types: (java.lang.String, java.lang.String, sample$_run_closure1_closure3) values: [http://hoge/svn/trunk, hoge, sample$_run_closure1_closure3@279fedbd] Possible solutions: run(), run(), any(), find(), wait(), dump() at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
ã¾ãå½ç¶ã¨ããã°å½ç¶ãªã®ã§ãããGroovyã®DSLã¨å¼ã°ãã¦ãããã®ã¯ãDSLãæ¸ãå ´æã«å®è¡æããããããã³ã³ããã¹ããªãã¸ã§ã¯ããã¯ãã¤ãã¦ãããã³ã³ããã¹ããªãã¸ã§ã¯ãä¸ã®ã¡ã½ããâä¸è¨ã ã¨svn(...)
ãå¼ã¶ãã¨ã«ãã£ã¦å®è£
ãã¦ããããã§ããã
ã¨ãããå¤é¨é¢æ°ã«ããã¨é¢æ°å¼ã³åºãå ã®ã³ã³ããã¹ããã¸ã£ãããããªããè¦ããªãã¨ããããã§ããããã¦å°ã£ãã
ãªã®ã§ãä¸è¨ã®è¦ããåªæãsvnRepositories([...])
ã®åã«æã¿ã¾ãã
scm { svnRepositories.delegate = delegate // è¦ããåªæ svnRepositories([ [remote: 'http://hoge/svn/trunk', local: 'hoge'], [remote: 'http://fuga/svn/trunk', local: 'fuga'], [remote: 'http://baz/svn/trunk', local: 'baz'], ]) }
ãã®è¦ããåªæããããã¾ãããããã«ãªãã¾ããåæ§ã«DSLå ã§é¢æ°ãããã ããããå ´åã¯ä¸è¨åªæãæãã°ããã¾ãã
ï¼delegate
ã§ã³ã³ããã¹ããªãã¸ã§ã¯ããåç
§ããããã«é¢æ°ã®ååã®ããããã£ã«ãããããè¨å®ãããã¨ã§ããã®é¢æ°å
ã®ã³ã³ããã¹ããªãã¸ã§ã¯ããæ¸ãæãããã¨ãã§ããã®ã§ãé¢æ°å¼ã³åºãå
ã®ã³ã³ããã¹ããªãã¸ã§ã¯ããä¼æããã¦ãã£ã¦ããããã§ãããæ£ç´Groovyã¯ã¾ã£ãã詳ãããªãã®ã§ãå³å¯ã«ã©ããªã£ã¦ããã®ãç¥ãã¾ããããï¼