I created this Groovy script, which relies on PARENT_JOB_NAME and
PARENT_JOB_NUMBER as params, but could be be better expanded to look at
it's parent directly rather than relying on those.
Progresses up the tree of triggered jobs, collecting change notes, then
pumps it all into a new param RELEASE_NOTES which can then be used by
HockeyApp...
import hudson.model.*
// Function makes it easier with recursion
def getBuildChangeLog(thisBuild) {
def thisLog = []
if (!thisBuild.changeSet.isEmptySet()) {
thisLog.addAll(thisBuild.changeSet.getItems())
}
for (cause in thisBuild.causes) {
if (cause.class.toString().contains("UpstreamCause")) {
def upProject = hudson.model.Hudson.instance.getItemByFullName(cause.
upstreamProject)
def upBuild = upProject.getBuildByNumber(cause.upstreamBuild)
thisLog.addAll(getBuildChangeLog(upBuild))
}
}
return thisLog
}
// =============================================
// Relies on some vars to be passed to find parent.
def buildVars = build.buildVariableResolver
// If "RELEASE_NOTES" has data, just keep it.
if (buildVars.resolve("RELEASE_NOTES")?.trim()) {
return;
}
def parentJob = hudson.model.Hudson.instance.getItemByFullName(buildVars.
resolve("PARENT_JOB_NAME"))
def parentBuild = parentJob.getBuildByNumber(buildVars.resolve(
"PARENT_JOB_NUMBER").toInteger())
def parentEnv = parentBuild.getEnvironment()
def changeLog = getBuildChangeLog(build)
def releaseNotes = "##Release Notes\n"
if (parentEnv.containsKey("GIT_COMMIT")) {
def gitCommit = parentEnv["GIT_COMMIT"]
def shortGitCommit = gitCommit[0..6]
releaseNotes += "Git Hash: " + shortGitCommit + "\n"
}
else if (parentEnv.containsKey("P4_CHANGELIST")) {
releaseNotes += "Perforce changelist: " + parentEnv["P4_CHANGELIST"] +
"\n"
}
if (changeLog.empty) {
releaseNotes += "###No changes since previous build"
}
else {
releaseNotes += "###Change Log:\n"
changeLog.each {
releaseNotes += "* ${it.msg}\n"
}
}
println releaseNotes
newParam = new StringParameterValue('RELEASE_NOTES', releaseNotes)
// Note: this assumes that params are already in use
def curParams = build.getAction(ParametersAction.class)
build.replaceAction(curParams.merge(new ParametersAction(newParam)))
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/309bf04a-4d52-420e-98cc-ea561ce3d591%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.