某些事情正在触发您的 Jenkins 工作 - 您轮询您的 SVN 存储库,或者您有一个 SVN 触发器,如此处所述。
在这两种方式中,您都可以使用已配置的
- 源代码管理:颠覆
- 退房策略:尽可能使用'svn update'
然后启动 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()
但是在这个阶段,文件已经在你的构建机器上了!changeSet 包含所有已在 svn update 中的项目。所以只需使用路径来处理它们。例如,您可以使用以下方法为每个更改的文件启动 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.")
}
}