Skip to content

Instantly share code, notes, and snippets.

@jimklimov
Created October 24, 2023 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimklimov/4c489b7ccbd5ce89b293cea483b9f6fd to your computer and use it in GitHub Desktop.
Save jimklimov/4c489b7ccbd5ce89b293cea483b9f6fd to your computer and use it in GitHub Desktop.
Jenkins - investigate job causes (e.g. to find SCM sources)
// Paste to your JENKINS_URL/script console:
def job = Jenkins.instance.getItemByFullName("org/repo/branch")
println "job: ${job}"
def build = job.getBuildByNumber(123)
println build
def commitHashForBuild(build) {
def scmAction = null
build?.actions.each { action ->
println "action: <${action?.getClass()}>'${action}'"
if (action instanceof jenkins.scm.api.SCMRevisionAction)
scmAction = action
}
println "scmAction: <${scmAction?.getClass()}>'${scmAction}'"
println "scmAction.revision: <${scmAction?.revision?.getClass()}>'${scmAction?.revision}'"
println "scmAction.revision.hash: <${scmAction?.revision?.hash?.getClass()}>'${scmAction?.revision?.hash}'"
return scmAction?.revision?.hash
}
println commitHashForBuild(build)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment