-1

I am trying to get the tagged commit hash. From terminal command is working fine:

Command line image

But when I am running the same command from sh script like this:

tagged_commit = sh(returnStdout: true, script: """
                                    git rev-list -1 v1
                                    """)

It is showing me this error.

enter image description here

I have tried all the commands listed here on this link: How to tell which commit a tag points to in Git?

For all these commands it's showing the same error.

Note: I am trying to use this from groovy.

torek
  • 448,244
  • 59
  • 642
  • 775
Mudit Singh
  • 117
  • 2
  • 9

1 Answers1

1

This is a Jenkins issue, not a Git issue and not a groovy issue. When Jenkins clones a Git repository, it often uses a shallow and/or single-branch clone that omits lots of names, including tag names like v1. Such a clone must be expanded to a full—or at least, less-shallow—clone, or made initially as a full clone.

I have used, but never actually administered, Jenkins, and the documentation I could find on Jenkins was always woefully inadequate, so I do not know how to control the initial clone. If necessary, see existing SO postings on how to convert a shallow clone to a full clone.

torek
  • 448,244
  • 59
  • 642
  • 775