Continuing on my question here: Jenkins pass or fail build on external executable
My build process now builds from source using MS Build, and executes a custom progr
// 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)
i have created a simple jenkins plugin to do that ...
https://github.com/rmalchow/changelog-appender
this takes creates a list of changesets from all builds since the last successful one, and writes those into a file, with a headline containing the version or build number and the date.
UPDATE:
this was for an old version of jenkins, and it hadn't been updated in a long time (we switched to gitlab-ci), so i took down that repo.
Here's what I did to add my own log to the normal Jenkins 'Changes' link per build: I ended up having to write my svn ant routines (using svnant) to do checkouts and updates etc...
My Trick To Make it Work:
1.) Under "Source Code Management" add "Subversion Modules". Do not fill out the section. I do not want it to check anything out. I have to do this to make Jenkins show the changelog.xml file I create, otherwise it can exist but Jenkins will not show it. In the job config.xml file you will see SCM...null... without this. When you add the empty svn repo, it thinks you are using svn and then lets your changelog.xml show up. (who knows how long this will work?)
In your build you want to do these steps in this order:
2.) write a create-changelog target. it should find the revision of code in your build folder. find the revision of code in svn. do svn log asXml="true" or "--xml" from start-rev to stop-rev. concat multiple log files together if needed to create ${Jenkins_Home}/jobs/${MYJOB}/builds/${BUILD_NUMBER}/changelog.xml
3.) now you can delete $workspace area if you want to.
4.) svn checkout of update
5.) build
6.) after build, 'Changes' link will show your changelog.xml
Problems I had:
scm polling did not do tags.
scm url was not flexible enough.
groovy-postbuild-plugin messed up my jenkins ui so I could not use it at this time.
sidebar-link-plugin does not seem to let you do it for each build. You might be able to do something with other plugins for build history, but I did not pursue it at this point.
Me again :)
On the simplest end of the spectrum, to simply add another link on the sidebar, along with "Changes" and "Status" links, there is a sidebar-link plugin
https://wiki.jenkins-ci.org/display/JENKINS/Sidebar-Link+Plugin
It allows you to create a link on the job page (not individual job runs however), which can link to a absolute or a relative (to job's configuration) location. You can reference a file within the workspace by putting the following into the link URL:
ws/my_output.txt
This however implies that the file is always present in workspace, and at best it would show the result of the last job execution. Also, clicking the link would take you to the file in workspace, it won't show the rest of the Jenkins UI anymore.
A more advanced approach would be to use a Groovy Script
https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin
Look at examples #1 and #6
The stuff next to yellow exclamation icon is what had been added to the job's status page by this plugin, and this is fully customizable and allows HTML code. This however requires knowing Groovy script, but the examples provide enough to do something quick