# Accessing SharedLibrary HEAD Commit-ID in build

**URL:** <https://community.jenkins.io/t/accessing-sharedlibrary-head-commit-id-in-build/1614>\
**Category:** Using Jenkins\
**Created:** [February 22, 2022, 1:59pm UTC](https://community.jenkins.io/t/accessing-sharedlibrary-head-commit-id-in-build/1614 "2022-02-22T13:59:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![manfred](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@manfred](https://community.jenkins.io/u/manfred)\
**Post date:** [February 22, 2022, 1:59pm UTC](https://community.jenkins.io/t/accessing-sharedlibrary-head-commit-id-in-build/1614/1 "2022-02-22T13:59:53Z")

</div>

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]

[1]: [https://stackoverflow.com/questions/42426638/where-does-the-jenkins-shared-library-files-get-stored#:~:text=If%20the%20shared%20library%20is,occupied%20by%20another%20concurrent%20build](https://stackoverflow.com/questions/42426638/where-does-the-jenkins-shared-library-files-get-stored#:%7E:text=If%20the%20shared%20library%20is,occupied%20by%20another%20concurrent%20build)).  
[2]: [[SECURITY-2422][SECURITY-2441][SECURITY-2463][SECURITY-2476][SECURITY… · jenkinsci/workflow-cps-global-lib-plugin@ace0de3 · GitHub](https://github.com/jenkinsci/workflow-cps-global-lib-plugin/commit/ace0de3c2d691662021ea10306eeb407da6b6365)

---

<div class="post-metadata">

**Author:** ![MadsJakobsen](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/madsjakobsen/32/129_2.png) [@MadsJakobsen](https://community.jenkins.io/u/MadsJakobsen)\
**Post date:** [February 22, 2022, 4:10pm UTC](https://community.jenkins.io/t/accessing-sharedlibrary-head-commit-id-in-build/1614/2 "2022-02-22T16:10:56Z")

</div>

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

```auto
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)
buildActions.each{ 
    println it.remoteUrls
    println it.getLastBuiltRevision().getSha1String()
}

```

---

<div class="post-metadata">

**Author:** ![manfred](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@manfred](https://community.jenkins.io/u/manfred)\
**Post date:** [February 22, 2022, 5:37pm UTC](https://community.jenkins.io/t/accessing-sharedlibrary-head-commit-id-in-build/1614/3 "2022-02-22T17:37:56Z")

</div>

It works! Thank you (:
