Use custom environmental variables when building an Azure Static Web App with Bitbucket pipelines

A mouthful of a title, I know, but when it comes to deploying apps to Azure using Bitbucket, it lacks the latest options, which are available to GitHub or Azure DevOps pipelines.

Since Azure insists on building the app for you passing down configs at build time (like a backend API URL) might be a hassle. To allow this build pipelines for GitHub and Azure DevOps have the env option, but Bitbucket’s pipeline does not.

To work around this problem I used the option to pass a custom build command and prepended the config I needed.

APP_BUILD_COMMAND allows passing the commands to build the app. I have configured my $prod_api as a variable for the Production environment in the repo’s deployment settings, and I point to it in line 6.

deployment: Production