Skip to content

Instantly share code, notes, and snippets.

@jimklimov
Last active December 9, 2024 15:47
Show Gist options
  • Save jimklimov/a8dc06eacdf05eff7edc2bb69f42c0f2 to your computer and use it in GitHub Desktop.
Save jimklimov/a8dc06eacdf05eff7edc2bb69f42c0f2 to your computer and use it in GitHub Desktop.
Jenkins SCM Changesets investigation
def b = Jenkins.instance.getItem("job-name").getBuildByNumber(1234)
println("Build name:\t${b}")
def mapCommitScm = [:]
b.getSCMs().each { scm ->
println("SCM:\t${scm}")
println("* Key:\t${scm.getKey()}")
println("* Branches:\t${scm.getBranches()}")
//println("* DN:\t${scm.getDisplayName()}")
//println("* URL:\t${scm.guessBrowser()?.repoUrl}")
println("* Commit:\t${scm?.getBuildData(b)?.getLastBuiltRevision()}")
mapCommitScm[scm?.getBuildData(b)?.getLastBuiltRevision()?.getSha1String()] = scm
println("* URCs:\t${scm?.getUserRemoteConfigs()}")
scm?.getUserRemoteConfigs()?.each {
println("* URC:\tname:${it.getName()} ~ refspec:${it.getRefspec()} ~ url:${it.getUrl()}")
}
println("* Repos:\t${scm?.getRepositories()?.each{it.getName()}}")
scm?.getRepositories()?.each{
println(it.getName())
it.getFetchRefSpecs()?.each{
println(it.getSource())
println(it.getDestination())
}
}
}
def c = b.changeSets.collectMany { it.toList().collect { it.author } }.unique()
println("Unique authors:\t${c}")
println("Culprits:\t${b.getCulprits()}")
b.changeSets.each { set ->
println("=====\n" + set + " => [" + set.getKind() + "] " + set.getBrowser()?.getChangeSetLink(set) + " (" + set.browser?.repoUrl + ")")
set.each { entry ->
println(entry.toString() + " => ")
println("getAuthor:\t" + entry.getAuthor())
println("getAuthorName:\t" + entry.getAuthorName())
println("getAuthorEmail:\t" + entry.getAuthorEmail())
println("getBranch:\t" + entry.getBranch())
println("getId:\t" + entry.getId())
println("getRevision:\t" + entry.getRevision())
println("getCommitId:\t" + entry.getCommitId())
println("getDate:\t" + entry.getDate())
println("getTimestamp:\t" + entry.getTimestamp())
println("getComment:\t" + entry.getComment())
println("getCommentAnnotated:\t" + entry.getCommentAnnotated())
println("getMsg:\t" + entry.getMsg())
println("getPaths:\t" + entry.getPaths())
println("getAffectedFiles:\t" + entry.getAffectedFiles())
println("getAffectedPaths:\t" + entry.getAffectedPaths())
println("")
println("REPO URL:\t" + mapCommitScm[entry.getRevision()]?.getKey())
println("")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment