Global variable incremented in every build

If you don’t need cross-branch storage then you can write these infos into the Build Cache (docs: http://devcenter.bitrise.io/caching/about-caching/).

Just add the Cache:Pull and Cache:Push steps to your workflow (Pull before you’d use the file/info/cache, and Push after you update it. E.g. Pull right after Git Clone, and Push at the very end of the workflow.), and then write your info into a file.

E.g. to write it into a file inside the cache dir, using a Script step, you can write something like this:

#!/bin/bash
set -ex

file_pth="$BITRISE_CACHE_DIR/last_release_build_number"
echo "$BITRISE_BUILD_NUMBER" > "$file_pth"

To read it from the file and expose it as an env var (BITRISE_LAST_RELEASE_BUILD_NUMBER) using envman (related docs: http://devcenter.bitrise.io/tips-and-tricks/expose-environment-variable/) in a Script step:

#!/bin/bash
set -ex

file_pth="$BITRISE_CACHE_DIR/last_release_build_number"

if [ ! -f "$file_pth" ] ; then
  echo " (!) File does not exist"
  exit 0
  # or if you want to fail in this case:
  # exit 1
fi

# read the value from the file
value_from_file="$(cat $file_pth)"

# expose the value as an env var for other steps
envman add --key BITRISE_LAST_RELEASE_BUILD_NUMBER --value "$value_from_file"

This will work if you don’t need cross-branch sharing. As described in the cache docs (http://devcenter.bitrise.io/caching/about-caching/) a build running on feature/A can’t write into the cache of master, or any other branch’s cache, only into its own.

But if you only read & write this “last release” info on a specific branch this will work.