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:
The issue was that the Commit with an Actual Tag, did work, but subsequent commits without tags will fail with the above error.fatal: No names found, cannot describe anything.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.