我正在使用Groovy DSL Build Flow plugin运行具有不同参数的其他作业。
最后,我将其收集到XML格式:
<testsuite tests='1'>
<testcase name='build_1' build_number='#882'>
<failure />
</testcase>
</testsuite>
我想将此XML写入文件。
我试过
def file = new File("report.xml")
file << result
其中result
正是文件内容。但是,在构建完成后,我没有看到任何文件。
以下是创建XML文件的代码片段:
writer = new StringWriter()
builder = new groovy.xml.MarkupBuilder(writer)
builder.testsuite(tests: builds.size()) {
for (bld in builds) {
def buildName = bld.key
def numberOfBuild = hudson.console.HyperlinkNote.encodeTo("/" + bld.value.getUrl(),
String.valueOf(bld.value.getDisplayName()))
def statusOfBuild = hudson.console.HyperlinkNote.encodeTo('/' + bld.value.getUrl()
+ "console", bld.value.result.toString())
if (statusOfBuild.contains("FAILURE")) {
testcase(name: "$buildName", build_number: "$numberOfBuild") {
failure()
}
} else {
testcase(name: "$buildName", build_number: "$numberOfBuild")
}
build.setResult(build.result.combine(bld.value.result))
}
}
println writer.toString()
def file = new File("report.xml")
file << result
我无法找到任何合理的创建文件的解决方案。
如何在此版本的文件夹中创建此文件?
答案 0 :(得分:0)
经过谷歌搜索和深度调试后,我解决了这个问题:
def file = new File(build.workspace.toString() + "/report.xml")
writer = file.newWriter()
builder = new groovy.xml.MarkupBuilder(writer)
// create correct repport file
builder.testsuites() {
builder.testsuite(name: "tms-edge-load", tests: builds.size()) {
for (bld in builds) {
def buildName = bld.key
def statusOfBuild = hudson.console.HyperlinkNote.encodeTo('/' + bld.value.getUrl()
+ "console", bld.value.result.toString())
println statusOfBuild
if (!statusOfBuild.contains("SUCCESS")) {
testcase(name: "$buildName") {
failure()
}
} else {
testcase(name: "$buildName")
}
}
}
}
println writer.toString()
writer.close()
文件已成功保存到项目工作区:
<testsuites>
<testsuite name='tms-edge-load' tests='1'>
<testcase name='build_1'>
<failure />
</testcase>
</testsuite>
</testsuites>