Ionic Pro: package app with firebase config based on branch

Hi,

I’m wondering if anyone has experience packaging apps with Ionic Pro where the branch built determines config that gets loaded?

I’m trying to use different Firebase database to support distributing apps for develop, staging, and production. I’m using Microsoft App Center (formerly HockeyApp) for the app distribution (as IonicView has been removed from the app store) and simply need to upload my .ipa files as needed.

In the Ionic Pro build configuration docs, there is the suggestion to keep different versions of package.js in each branch where a different build variation is necessary.

I was looking for an alternate solution as I don’t like the possibility that my environments could be broken by a simple mistake during a merge where part of package.js intended for one branch/environment is merged into another.

I attempted to source a script that picks up the branch name and sets the environment variable I need set when npm run build is called. This works locally but not in an Ionic Pro build.

My npm build script looks like this:

“build”: “. scripts/set-env.sh && if [ “$MY_ENV” = “prod” ]; then npm run ionic:build:prod; else npm run ionic:build; fi”,

scripts/set-env.sh is the file that tries to pick out the git branch using git rev-parse --abbrev-ref HEAD, which should provide the branch name but when run as part of an Ionic Pro build it just returns HEAD. I tried a number of variations on getting the branch name but all failed. It’s confusing given that in the build log it clearly indicates the commit checked out as a named branch, e.g. “Checking out 5b91afc8 as develop”.

Any suggestions on picking up the branch name or an alternative way to set an environment variable at the beginning of a build based on the branch would be much appreciated.

Thanks,
Jeff