${BITRISE_GIT_BRANCH} not working

I have a fastlane script for each platform (iOS and android) and for some reason this variable (BITRISE_GIT_BRANCH) is not working. I’m new to bitrise/ fastlane and apps in general, can you point me in the right direction to either set this variable correctly within bitrise or how to fix it within the script that references the BITRISE_GIT_BRANCH variable?

It was working previously, earlier in the year (2021) and before as I haven’t created this build process myself, I’ve inherited the pipeline that uses Bitrise so looking for help!

I have seen the following link which I also commented on but it didn’t help. We use feature branches for development and then eventually we’ll build beta releases using tags. I just want the variable to say build the branch it’s on (without the use of tags etc…)

If you are using tags or commit hashes to trigger the build then the branch information is not going to be present. Tags are based on commit hashes and they are not immediately discernible.

We were able to work around this because our CI automatically creates the tag and it includes the branch name in the tag name. We just added a step that parses the tag name and then initializes the BITRISE_GIT_BRANCH for the following steps to consume. To handle commit hash adhoc invocations, we put a check on steps that absolutely needs the branch name for a special environment variable that we cascaded to the devs to supply if they really want to build using a commit hash. Realistically only a few power devs use that route. :slight_smile:

thanks for the response, so has something changed how it works recently?

If I understand correctly you are creating tags and then using them to work out the branch…(?)

We’re using feature branches off our develop branch, say “feature/fix_fastane” and then when this is complete we merge this into the develop branch and then into the master branch and then and only then do we use tags to identify a release. With this in mind, you’re approach wouldn’t work for us…(?) :frowning:

Any ideas?

Based on your linked discussion it seemed the Bitrise team did make a change around March.

In your usage scenario, wouldn’t it be safe to assume that all your tags are based from master? If it is then you can just set that as the branch value. If you need the source branch to be reflected then you will need a way to record that in the tag itself so if you have that in the build execution creating the branch then you can create an annotated tag and then adjust your later builds to check the annotation if a tag was used as the starting point.

ciao!

I had several issues with that, and I ended up with this workaround:

In the bitrise workflow step:

export CURRENT_BRANCH="${BITRISE_GIT_BRANCH}"
bash ./myscript.sh

In my script:

if [ -z "$CURRENT_BRANCH" ]; then
  CURRENT_BRANCH=$(git branch --show-current)
fi
if [ -z "$CURRENT_BRANCH" ]; then
  CURRENT_BRANCH=$(basename $(git name-rev --name-only HEAD))
fi

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.