Version Number Environment Variable

For this step - is there a way to get the value which was set in the current info.plist in the git repo? Basically we want to use the version number set manually by us in the project. But want to avoid changing it everytime on bitrise as well. So would be handy if after a git clone, we could get an environment variable that exposes the version number in the project.

Would be handy to add it in the git tag step, etc as well.

There’s a community contributed step (not maintained by us) which can do exactly this: Xcode Project Info. It exports both the Version and the Build numbers from the Info.plist

After this you can use these environment variables (XPI_VERSION and XPI_BUILD) in any other step.

Alternatively you can use a Script step and PlistBuddy to expose these infos, something like:

set -ex

# get the values
version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${INFO_PLIST_PATH}")
build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFO_PLIST_PATH}")

# expose the env vars for subsequent steps
envman add --key XPI_VERSION --value "${version}"
envman add --key XPI_BUILD --value "${build}"

Source (from the Step’s code):


Thanks Viktor. In the Set Xcode Project Build Number Set (image attached) if we add an offset to the Bitrise Build Number, does that change the $BITRISE_BUILD_NUMBER for future use? Basically our last step is to add a git tag but we want the tag to include the correct build number. Ofcourse with the offset in the previous step, it may not be accurate.

For now, I have added the step Xcode Project Info again before the git_tag step so it gets the updated value.

PS: I can post this as a separate question if you think its helpful.

Unfortunately no, you can’t change the $BITRISE_BUILD_NUMBER for subsequent builds, it’s generated by every time when a new build is started.

If you use these steps (the Set Xcode Build Number and Xcode Projec Info steps) it will work, but it won’t be in sync with the build number on (as that’s a read only value, generated right when the build starts). During the build the number will be in sync, as the Xcode Project Info step reads the value from Info.plist, and the Set Xcode Build Number step writes the value into Info.plist

In general the best is to not to use the offset, as that way you can have a “perfect sync” between steps and the web UI.

We have removed the offset as per your suggestion. However, if someone wants to get the updated value, a hack would be the following:

Add the step Xcode Project Info again before the git tag step so it gets the updated value from info.plist again. Then use $XPI_BUILD for the latest value.

1 Like

Indeed, if you want to get the build number which includes the offset, you have to have the steps in this order:

  1. Set Xcode Build Number
  2. Xcode Project Info

This way Xcode Project Info reads the value previously set by Set Xcode Build Number.

Thanks for the note / insight @rahilbhansali !

1 Like

Adapted from this

set -x


if [ -z "$MARKETING_VERSION" ]; then
    echo "could not extract marketing version"
    exit 1
    echo "marketing version:"

if [ -z "$BUILD_VERSION" ]; then
    echo "could not extract build version"
    exit 1
    echo "build version:"

echo "new version:"
1 Like