2

When creating a build pipeline, is there is a way to get the git commit id and tag and consume them as build parameters when jenkins checks out a polled git repo?

TyMac
  • 783
  • 2
  • 9
  • 32
  • You can use a bash execution and run something like `git log -1 --pretty="%H"` to get the commit hash. You can then use this elsewhere. – Matt Clark May 04 '17 at 19:17
  • indeed. there are some further details and links over at http://stackoverflow.com/questions/43738237/capturing-shell-script-output-from-jenkins-pipeline/43739276#43739276 – burnettk May 04 '17 at 21:04
  • Thanks that works for the commit id but what about the tag? Right now I have git tag | tail -1 but that only makes sense if the commit is actually tagged... otherwise I'll just pick up the last tag. What can I do to make sure I pick up a tag that should correlate with the commit id? – TyMac May 05 '17 at 02:30
  • How about [git describe](https://git-scm.com/docs/git-describe)? – 1615903 May 05 '17 at 05:05
  • 1
    Does not seem to work: ~/chef-repo/cookbooks/base - - master - git describe fatal: No annotated tags can describe '90cc3dfebb14e9b8b42f68c3461793c0f90133bc'. However, there were unannotated tags: try --tags. ✘ ~/chef-repo/cookbooks/base - - master - git describe --tags v2.1.49 – TyMac May 10 '17 at 16:46

0 Answers0