Environment variables

Environment variables allow you to specify API keys, access tokens, or other secrets that your build requires, without having them checked into your repository.

Environment variables are made available during a build to any process that can use them, including custom build steps.

You can create regular environment variables which are available to all branches, or branch-specific environment variables which are only available for a specific branch.


Any environment variables set by buddybuild are available to all phases of a build.

However, environment variables set by scripts invoked by your build tool, tests, or other build-related operations, are only available while those scripts are executing.

For example, the environment variable BUILT_PRODUCTS_DIR is only available while Xcode is running, specifically when a Run Script is executing.

If you need to persist environment variables across script executions, you have a few options:

  • Specify the environment variables in the buddybuild dashboard — buddybuild takes care of making those environment variables available to every step of your builds.

  • Append export commands to the .bashrc file; .bashrc is sourced every time a (subsequent) Bash script is executed. For example, within buddybuild_postclone.sh you could define environment variables like this:

    APP_VERSION=$(node -pe "require('./package.json').version")
    echo "export APP_VERSION=$APP_VERSION" >> $HOME/.bashrc

    The first line captures the version key from your repository’s package.json file using node.js. The second line appends the environment variable definition to .bashrc.

  • If you’re not using Bash, write the definitions of the environment variables to a file, and read those definitions every time your scripts execute.

Creating default environment variables

Start by clicking on App Settings.

The buddybuild dashboard

In the left navigation, select Build settings, then the Environment tab.

The Default build configuration screen, with the Environment tab selected

In the Environment variables row, click Configure.

The Default build configuration screen, clicking the Configure button for Environment variables

Enter a name and value to create a default environment variable. Your environment variable is now ready to be consumed by your app at build time.

The Environment Variables screen

Create environment variables for a specific branch

You can also create environment variables for a specific branch by creating a branch-specific override.

Under Override build configuration, click Add a branch and select the branch you would like to create an environment variable for.

The Override build configuration area, with the branch selection dropdown open

Select Environment variables from the dropdown and click Configure.

The Override build configuration area, clicking the Configure button for the Environment variables option

Enter a name and value to create your branch-specific environment variable.

The Environment Variables screen for a specific branch

Consume the variable in your build

Your environment variables will be automatically consumed by tools that are expecting them.

Consume in your custom build scripts.

If you would like to access them in your custom build scripts, use the bash variable expansion syntax.

./Example.framework/run $Crashlytics_Token

That’s it! If you want to consume your variables from within your app, follow the Device Variables guide.

results matching ""

    No results matching ""