Search code examples
gitjenkinsjenkins-pipeline

Can I get the git hash from repo url?


I am working on creating a Jenkins job which takes a list of github repo url's as its input. I want to get the latest git hash from each of these repo's. But, I'm not sure how todo this without cloning each repo running git rev-parse --short HEAD. Does anyone know if there is a easy way I can fetch the latest git hash from just the github repo url?


Solution

  • git ls-remote $URL HEAD
    

    See the docs. Example:

    $ git ls-remote https://github.com/sqlobject/sqlobject.git HEAD
    32c1ce111d56025594083a8c8889994f205acc9c        HEAD
    

    For private repositories you need authentication.