When is BITBUCKET_TAG environment variable set?

Alex Soto June 13, 2016

This question is in reference to Atlassian Documentation: Environment variables in Bitbucket Pipelines

I've been experimenting with pushing commits and tags on master and other branches and I can't find a situation when the BITBUCKET_TAG environment variable is set.

 Under what scenario is the BITBUCKET_TAG set and triggers a pipelines build?

 

4 answers

0 votes
T. Klingenberg October 21, 2019

It is my current understanding that the  BITBUCKET_TAG environment variable is set if the pipeline that runs is a "tag" pipeline.

 

The value of BITBUCKET_TAG parameter is the name of the git tag that triggered the pipeline.

0 votes
tysonbul October 15, 2018

So I ran into this issue where I was unable to get the BITBUCKET_TAG variable to be set, and there was a few things I had to figure out to get the Tag value to set properly. First, I learned about git tags through this link:

http://alblue.bandlem.com/2011/04/git-tip-of-week-tags.html

The important thing to take from that was the comment about annotated tags versus lightweight. E.g. If you want to have git tags that trigger pipeline builds you'll want to have a git workflow of something along of the lines of:

git add .

git commit -m "comment about commit"

git tag -a v1.2.3 -m "Comment about release" # Note the -a flag

git show #(to check and see if the tag is set on the commit)

git push --follow-tags # This pushes both the latest commits and flags

The push --follow-tags is the second thing I learned from doing it, and what this does is trigger two builds (Which I wasn't expecting, but better than not having the Tag value set ever):

- One for the fact that there was a push of commits, which will do a pipeline run with ONLY the BITBUCKET_BRANCH value set

- One for the fact a tag was pushed, which will run with ONLY the BITBUCKET_TAG value set.

So I'm not sure if this is 100% how it was intended to be done, but that's the only solution I could find. Hope it helps someone down the road.

0 votes
Aruljothi J May 31, 2018

Screen Shot 2018-05-31 at 1.15.37 PM.pngThanks for your response Jeroen.

I would like to elaborate my issue here.

#Blackduck is opensource security scan software, when I run my pipeline with "analyze-with-blackduck" it will scan my branches(master/develop/future) and create/send report to blackduck server.

"analyze-with-blackduck"-this is the command which I am using for my branch scanning.

It will scan for master/develop/future branches not for TAGS.

We had a shell script to detect and scan the branches not for tags, now I am trying to scan Tags also but it's shows error.

I have updated my pipeline.yml and script:

image: :my-java-image-v1

pipelines:

tags:

   release_*:  #this is using for each new release.."*" is the issue.

     - step:

        caches:

           - maven

       script

      - mvn -B clean install -Dmaven.test.skip

     - analyze-with-blackduck . #This is a cmd for blackduck scanner

 Below pipeline is using for develop, it's working 

image:my-java-image-v1

pipelines:

develop:

     - step:

        caches:

           - maven

       script

      - mvn -B clean install -Dmaven.test.skip

     - analyze-with-blackduck . #This is a cmd for blackduck scanner

#We mentioned scan information on docker image.

 

Script:

$BITBUCKET_BRANCH=${BITBUCKET_BRANCH:-$1} #working 

$BITBUCKET_TAG=${BITBUCKET_TAG:-$1} #not working

echo $BITBUCKET_TAG

echo "TAG"

Aruljothi J May 31, 2018

any updates?

Aruljothi J June 1, 2018

This is similar with @[deleted] query.

0 votes
Jeroen De Raedt
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 16, 2016

Bitbucket Pipelines currently doesn't build pushed tags (it only builds the top commit of the push). 

Is there anything specific you are trying to achieve with Bitbucket tags?

Alex Soto June 16, 2016

I was prototyping how to migrate our deployment pipeline from Bamboo Cloud using tags as the trigger on specific branches.   (qa branch, tagging RELEASE-X, triggers deployment)

 

FYI - the documentation I reference in the original post documents a BITBUCKET_TAG environment variable kicks off a build!

 

BITBUCKET_TAGThe tag of a commit that kicked off the build. This value is only available on tags.
Deleted user August 11, 2016

We are also attempting to use the BITBUCKET_TAG environment variable without success. Specifically, when a commit is pushed to master, we are using Pipelines to package our code and upload the archive file to Artifactory. The archive file needs to include the version number (i.e. the tag on master), but the BITBUCKET_TAG environment variable isn't being set.

Alex Barnes October 9, 2017

On first read of Jeroen's answer he appears to suggest the env var BITBUCKET_TAG is pointless :)

 

I'm guessing you have to tag the commit locally prior to pushing the commit to the remote branch (Bitbucket). This would then kick off a build and have the tag available immediately.

Aruljothi J May 31, 2018

I am facing issue with BITBUCKET_TAG, when I am trying to scan my tag branch using blackduck software it will show "missing argument" issue.Some one please help me.

Jeroen De Raedt
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 31, 2018

Hi @Aruljothi J,

might be best to create a seperate question for this, since it is a different topic. 

Regarding your question, I am not entirely sure what blackduck software does, but keep in mind that the $BITBUCKET_TAG variable will only be set if you pushed a tag (i.e. not if you pushed a branch reference). 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events