【发布时间】:2016-09-21 23:17:39
【问题描述】:
我正在尝试让这个 Groovy 脚本在 Jenkins 中运行:
import java.lang.ProcessBuilder.Redirect
import hudson.model.*
import hudson.util.*
import hudson.scm.*
//I'm not sure that these 2 imports are correct:
import hudson.plugins.tfs.model.ChangeSet;
import hudson.plugins.tfs.model.ChangeSet.Item;
// work with current build
def build = Thread.currentThread()?.executable
// get ChangesSets with all changed items
def changeSet= build.getChangeSet()
List<Item> items = changeSet.getItems()
def affectedFiles = items.collect { it.paths }
// get file names
def fileNames = affectedFiles.flatten().findResults
// setup log files
def stdOutFile = "${build.rootDir}\\stdout_groovy.txt"
def stdErrFile = "${build.rootDir}\\stderr_groovy.txt"
//execute a command for each file
fileNames.each
{
def params = ["cmd.exe", "/C", "dir ${it}"]
def processBuilder = new ProcessBuilder(params)
// redirect stdout and stderr to log files
processBuilder.redirectOutput(new File(stdOutFile))
processBuilder.redirectError(new File(stdErrFile))
def process = processBuilder.start()
process.waitFor()
// print log files
println new File(stdOutFile).readLines()
System.err.println new File(stdErrFile).readLines()
}
我的目标是能够仅迭代已更改的文件并将这些文件复制到另一个位置。我正在尝试在Process only changed files 中创建与 TFS 一起使用的代码版本。我收到 2 个错误:
无法解析类 hudson.plugins.tfs.model.ChangeSet.Item
无法解析类 hudson.plugins.tfs.model.ChangeSet
这是有道理的,因为 Groovy 不知道从哪里获取 TFS 代码。 我在https://wiki.jenkins-ci.org/display/JENKINS/Team+Foundation+Server+Plugin 使用TFS 插件。我读过 Groovy 可以使用 Grape 进行依赖管理。如果 TFS 插件位于 http://mvnrepository.com/ 中,那么我可以使用它让 Groovy 获取如下所示的最新代码:
@Grapes(
@Grab(group='org.apache.maven.scm', module='maven-scm-provider-tfs', version='1.9.4')
)
但是,TFS 插件不在http://mvnrepository.com/ 中。插件源在https://github.com/jenkinsci/tfs-plugin。那么,我怎样才能告诉 Groovy 从哪里获取代码呢?理想情况下,我不必将插件代码复制到我的构建机器并处理使其保持最新状态。 (我确定我的代码中存在错误。我只是想解决依赖关系管理(但请随时指出编码错误))。谢谢。
【问题讨论】: