Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using Git Describe --Tags does not return expected result inside Pipeline

sscholle
July 15, 2025

Im trying to export a VERSION Variable using both the latest Git Tag and the BUILD NUMBER in my pipeline:

image: python:3.8

pipelines:
  branches:
    main:
      - step:
          name: Set Version ENV
          script:
            - echo "VERSION=$(git describe --tags `git rev-list --tags --max-count=1`).${BITBUCKET_BUILD_NUMBER}" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
            # Expect similar output as below
            # - echo "VERSION=0.1.${BITBUCKET_BUILD_NUMBER}" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
          output-variables:
            - VERSION

 

But the script output results in an error:

fatal: No names found, cannot describe anything.

The issue was that the Commit with an Actual Tag, did work, but subsequent commits without tags will fail with the above error.

Running this command in my repo locally will always return the most recent Tag, no matter if the tag is on the Current Commit or Not:

git describe --tags `git rev-list --tags --max-count=1`

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 16, 2025

Hi @sscholle,

A pipeline that runs on a branches definition, like the one you provided here, will clone the last 50 commits of that branch by default. Commits older than that and commits from different branches will not be present on the clone where the pipeline build runs.

I assume that your local repo has all commits of the main branch, and possibly other branches as well, which is why you see a different behavior.

You can use the depth option for this step in your bitbucket-pipelines.yml and specify a full depth clone:

image: python:3.8

pipelines:
branches:
main:
- step:
clone:
depth: full
name: Set Version ENV
script:
- echo "VERSION=$(git describe --tags `git rev-list --tags --max-count=1`).${BITBUCKET_BUILD_NUMBER}" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
# Expect similar output as below
# - echo "VERSION=0.1.${BITBUCKET_BUILD_NUMBER}" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
output-variables:
- VERSION

Then the clone of this step will have all commits of the repo available and the Git command should return the most recent tag.

Please feel free to let me know how it goes and if you have any questions!

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events