Version Number Environment Variable

#1

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.

0 Likes

How to get App Version and Build number in Xcode Project? Is there a variable?
#2

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:

#!/bin/bash
set -ex

# get the values
INFO_PLIST_PATH=./path/to/Info.plist
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): https://github.com/tadija/bitrise-step-xcode-project-info/blob/master/step.sh

2 Likes

#3

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.

0 Likes

Automatic build numbering
#4

Unfortunately no, you can’t change the $BITRISE_BUILD_NUMBER for subsequent builds, it’s generated by bitrise.io 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 bitrise.io (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 bitrise.io web UI.

0 Likes

#5

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

#6

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

#7

Adapted from this

set -x

PROJECT_FILE_PATH="path/to/project.pbxproj"
MARKETING_VERSION=`sed -n '/MARKETING_VERSION/{s/MARKETING_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' $PROJECT_FILE_PATH`
BUILD_VERSION=`sed -n '/CURRENT_PROJECT_VERSION/{s/CURRENT_PROJECT_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' $PROJECT_FILE_PATH`

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

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

NEW_VERSION="${MARKETING_VERSION}+${BUILD_VERSION}"
echo "new version:"
echo $NEW_VERSION
1 Like