Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get BITBUCKET_BRANCH in a step within tags?


I have a tag defined as following. And I want to retrieve the BRANCH name from where this pipeline is triggered. As per the documentation, the $BITBUCKET_BRANCH variable is only available for branches. 

I need to get BRANCH name for the step "Send Slack". Any suggestion would be appreciated.

- step:
name: Deploying to Dev
deployment: dev
- git branch
- pipe: docker://<pipe_name>
- step:
name: Send Slack
- declare -x VERSION=$(cat version.txt)
- pipe: atlassian/slack-notify:0.3.2
MESSAGE: "Deployed from Pipeline to env:DEV project:${PROJECT} version:${VERSION} "


1 answer

0 votes

Hi @sayantan.roy

Pipelines don't provide the branch name variable because there is a conceptual problem here. A tag can be part of multiple branches. It references directly a commit and this commit can be part of multiple branches.

If you want to know what are the branches that contain a given tag, you can use the following git command:

git branch --contains tags/<TAG_NAME>

Depending on the tag that command will return one of the multiple branches and you will need to parse it to decide which branch will be the one feeding your script.

I hope that helps yo clarify the issue. 

Hi @Daniel Santos -

I tried doing exactly this, but it didn't give the expected result:

git branch --contains tags/patch-1263-5
Tag patch-1263-5 is in branch ['* (no branch)']


The same command in a local console (after the pipeline has completed and I do a git pull does give the expected result:

$ git branch --contains tags/patch-1263-5
* ISW-1263


So, why is it different from within the pipeline?  And is there some trick to get the pipeline to return the same branch(es) that I see in a local console?



Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

101 views 1 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you