Builds

The Git Workflow at the core of Ionic Pro allows you to push commits of your app code, which can then be used to trigger two distinct types of builds.

Deploy Builds

A deploy build is a build of your application that includes only the web assets (JavaScript, HTML, fonts, and images) which can be shipped out to customer via Deploy. Deploy builds are currently automatically triggered when you push code to the Ionic Pro Remote or any branch that is connected to your app via the GitHub or Bitbucket integration. The basic steps of the deploy build are as follows:

  • npm install will run to install any dependencies you have.
  • npm run build will run if a build script is detected in the scripts section of your package.json in order to build the web assets for your application.
  • The www directory with your built application will be stored and made available for live updates via Deploy
  • You can find the history and status of your deploy builds in the side menu under Builds in the Deploy tab.

Package Builds

A package build is a native build of your application that is platform specific and can run on a physical device. Package builds produce apk files for Android and ipa files for iOS. Currently package builds are only available to customers on one of the paid plans and must manually be triggered from the dashboard. The basic steps of the package build are as follows:

  • npm install will run to install any dependencies you have.
  • npm run build will run if a build script is detected in the scripts section of your package.json in order to build the web assets for your application.
  • cordova platform add [ios|android] will run with the platform you have configured NOTE: DO NOT commit your platforms directory as this will cause your build to fail.
  • cordova build [ios|android] will run with the platform and options you have configured and generate the ipa or apk file
  • The generated ipa or apk will be stored and available for you to download from the dashboard
  • You can find the history and status of your package builds as well as download successful builds in the side menu under Builds in the Package tab.

Build Environments

Every time a Build occurs, it’s done in a secure environment where we provide some predefined variables which are key/value pairs that are made available in the environment and are available by using process.env.MY_VAR syntax in NodeJS or via $MY_VAR syntax in a standard shell script. These variables can be leveraged to customize the build and outputs.

The following environment variables are provided in every build, which can be accessed in build scripts:

  • CI_APP_ID (string): Your Ionic app’s unique ID.
  • CI_APP_NAME (string): Your Ionic app’s name.
  • CI_GIT_COMMIT_SHA (string): The SHA for the commit on which the build was run.
  • CI_GIT_REF (string): The git ref from which the build was created (i.e. master).
  • CI_GIT_REF_TYPE (string): The git ref type (i.e. branch).

For example you could replace your build script in the package.json with a custom shell script that reads the branch and triggers a custom build.

// customize the build script in the package.json
{
...
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "./mybuild.sh",
        "lint": "ionic-app-scripts lint",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
...
#!/bin/bash
if [ "$CI_GIT_REF" = "master" ]; then
    npx ionic-app-scripts build --prod
else
    npx ionic-app-scripts build
fi

As of @ionic/[email protected] you can also use environment variables directly in your source code and they will be replaced at build time so that you can customize your code based on the environment.

For example:

productionConfig = {
  api: 'https://my.production.api.com',
  analyticsKey: 'my-production-key'
}
stagingConfig = {
  api: 'https://my.staging.api.com',
  analyticsKey: 'my-staging-key'
}

localConfig = {
  api: 'https://localhost:7000'
  analyticsKey: 'my-local-key'
}

switch (process.env.CI_GIT_REF) {
  case 'master':
    return productionConfig;
  case 'staging':
    return stagingConfig;
  default:
    return localConfig;
}

API

Native

General