Accessing SharedLibrary HEAD Commit-ID in build

Hello (:

We are using Jenkins and our build relies heavily on SharedLibraries. In our build we want to get the HEAD Commit-ID of our SharedLibrary, to be more specific: The HEAD commit id of the shared library which was checked out for the ongoing build. Do you have an idea how to manage this? Is there a default location where the checkout out shared library is stored?

We do not need the command for getting the HEAD commit id as we already know it: git rev-parse HEAD

We need to get to the location of the shared library on Jenkins in order to execute this command.

The location specified in [1] does not work anymore. I think this is due to the following fix [2]

[2]: [SECURITY-2422][SECURITY-2441][SECURITY-2463][SECURITY-2476][SECURITY… · jenkinsci/workflow-cps-global-lib-plugin@ace0de3 · GitHub

this is not very clean, but you could look at the build actions for the job and compare it to the libraries.

import jenkins.model.Jenkins

library identifier: "library1"
library identifier: "library2"

Jenkins jenkins = Jenkins.getInstance()
def globalLibraries = jenkins.getDescriptor("org.jenkinsci.plugins.workflow.libs.GlobalLibraries")

globalLibraries.getLibraries().collect {
    println it.getRetriever().getScm().getRemote()

def buildActions = currentBuild.rawBuild.getActions(hudson.plugins.git.util.BuildData.class)
    println it.remoteUrls
    println it.getLastBuiltRevision().getSha1String()

It works! Thank you (: