"git describe --tags" in Harness CI run step post cloning the git repo gets commit SHA instead of the tag

As mentioned here CI Pipeline would be configured with a Codebase that specifies the code repo (input) that the Pipeline uses to build the artifact (output).

When you run a CI pipelien with codebase configured and enabled, we clone the default codebase into its workspace as part of the setup process. You can then run the git command against this cloned repo.

However, when you run the command git describe --tags , we would get the SHA of the head commit instead of the tag name, or you may get the below error in the run step where you run the describe command.

+ git describe --tags
fatal: No names found, cannot describe anything.

This is happening as we directly checkout to FETCH_HEAD as part of the default clone code base step which is a sha, we don’t have the tag information at this point.

We would need to run git fetch --tags before running git describe --tags in run step to get this working. Also if the repositary is private, run step explicitly needs to authenticate to git. We can add the below command before running git fetch command to get this working.

cat <<EOF > ${HOME}/.netrc
1 Like