You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/U4SReCE2tok/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
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)))