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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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? Edited

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.

tags:
'dev/trigger':
- step:
name: Deploying to Dev
deployment: dev
script:
- git branch
- pipe: docker://<pipe_name>
variables:
NAMESPACE: $NAMESPACE
BUILD_HELM: $BUILD_HELM
- step:
name: Send Slack
script:
- declare -x VERSION=$(cat version.txt)
- pipe: atlassian/slack-notify:0.3.2
variables:
WEBHOOK_URL: $SLACK_URL
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?

 

-Jeff

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket Pipelines

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

1,227 views 0 3
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