有什麼東西觸發你的詹金斯的工作 - 你輪詢您的SVN倉庫或者你有一個SVN觸發作爲descriped here。
在這兩種方式,你將配置
- 源代碼,管理開始你的工作:顛覆
- 退房策略:使用「SVN更新」儘可能
然後你開始你的Groovy系統腳本:
import hudson.model.*
import hudson.util.*
import hudson.scm.*
// work with current build
// (does only work as groovy system script, not in the Jenkins shell)
def build = Thread.currentThread()?.executable
// for testing, comment the line above and uncomment the job line
// and one of the build lines - use specific build (last build or build by number)
//def job = hudson.model.Hudson.instance.getItem("<your job name>")
//def build = job.getLastBuild()
//def build = job.getBuildByNumber(162)
// get ChangesSets with all changed items
def changeSet= build.getChangeSet()
def items = changeSet.getItems()
但是在這個階段,文件是al準備在你的機器上! changeSet包含已經在svn更新中的所有項目。所以只需使用路徑來處理它們。例如,您可以使用以下方式爲每個更改的文件啓動Jenkins作業:
void startJenkinsJob(jobName, param)
{
// Start another job
def job = Hudson.instance.getJob(jobName)
def anotherBuild
try {
def params = [
new StringParameterValue('StringParam', param),
]
def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(params))
println "Waiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
anotherBuild = future.get()
} catch (CancellationException x) {
throw new AbortException("${job.fullDisplayName} aborted.")
}
println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
// Check that it succeeded
build.result = anotherBuild.result
if (anotherBuild.result != SUCCESS && anotherBuild.result != UNSTABLE) {
// We abort this build right here and now.
throw new AbortException("${anotherBuild.fullDisplayName} failed.")
}
}