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} "
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you ever figure this out?
I'm getting the same exact result and I'm having a hard time trying to figure out how to restrict tags like `0.0.0` to only be on `master` 😓
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For me, the fix was a very special/secret incantation of both the following in a step (like this)
clone:
depth: full
And then in the "script"
- git checkout master
This was to ensure that I can run the following just to validate that a tag was in the master branch.
- export TAG_INFO=`git branch --contains tags/$BITBUCKET_TAG 2>/dev/null`
And wow... that was painful! Looking back I pushed 18 tags over an hour or so just to figure it out.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks for the hint with:
clone:
depth: full
it solved the problem for me too.
BTW: "git checkout" is not required for "git branch --contains"
For me it worked to use:
git branch -a --contains tags/${BITBUCKET_TAG}
or
git branch -r --contains tags/${BITBUCKET_TAG}
because there are no local branches the -r (remote branches) or -a (all branches) helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.