詹金斯的日志更改 [英] Log changes in Jenkins
本文介绍了詹金斯的日志更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里继续我的问题: Jenkins在外部可执行文件上通过还是失败
Continuing on my question here: Jenkins pass or fail build on external executable
我的构建过程现在使用MS Build从源进行构建,并在构建过程中执行自定义程序.我在程序中写到控制台的所有内容都记录在控制台输出中.
My build process now builds from source using MS Build, and executes a custom program as part of the build process. Anything that I am writing to the console in my program is being logged in the console output.
但是,我还想在用户界面的更改"和/或状态"部分中记录一些条目(类似于SVN所做的事情).
However, I would also like to log some entries in the "Changes" and/or the "Status" portions on the user interface (similar to what SVN does).
这怎么办?
推荐答案
// This is a deliciously convoluted and fragile hack to force Jenkins to show the
// changes via a Groovy Postbuild script:
// fake a Subversion changelog.xml file
changes = new File(manager.build.getRootDir(), "../../workspace/changes.txt")
changelog = new File(manager.build.getRootDir(), "changelog.xml")
changelog.withWriter {
out ->
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?><log><logentry revision=\""
+ manager.build.number + "\"><date>"
+ new java.util.Date() + "</date><paths>")
message = ""
changes.eachLine {
line ->
if (line.startsWith("./")) line = line.substring(2)
if (!".checksums".equals(line)) {
out.println("<path action=\"M\">" + line + "</path>")
message += line + "\n"
}
}
out.println("</paths><msg>" + message + "</msg></logentry></log>")
}
// get an instance of the SubversionChangeLogParser
import java.net.URL;
import java.net.URLClassLoader;
baseDir = new File(jenkins.model.Jenkins.getInstance().getRootDir(),
"plugins/subversion/WEB-INF/")
urls = new URL[2];
urls[0] = new File(baseDir, "classes/").toURI().toURL()
urls[1] = new File(baseDir, "lib/svnkit-1.3.4-hudson-2.jar").toURI().toURL()
loader = new URLClassLoader(urls, manager.getClass().getClassLoader())
svn = loader.loadClass("hudson.scm.SubversionChangeLogParser").newInstance()
// force the current build to take that parser, parse the changelog.xml,
// and force it down AbstractBuild's throat, too
scmField = manager.build.getClass().getSuperclass().getSuperclass().getDeclaredField("scm")
scmField.setAccessible(true)
scmField.set(manager.build, svn)
changeSet = svn.parse(manager.build, changelog)
changeSetField = manager.build.getClass().getSuperclass().getSuperclass().getDeclaredField("changeSet");
changeSetField.setAccessible(true)
import java.lang.ref.WeakReference;
if (changeSetField.getDeclaringClass().isAssignableFrom(WeakReference.class))
changeSet = new WeakReference(changeSet)
changeSetField.set(manager.build, changeSet)
这篇关于詹金斯的日志更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文