Built-in environment variables using Flutter workflow editor

Useful variables exported during builds using Flutter workflow editor

Codemagic exports several built-in environment variables during the build that you can use in scripts to customize the build process. Environment variables added by user will override Codemagic defaults. You can check which environment variables are exported by inserting the following script before or after any of the default build steps:

  scripts:
    - name: Set up app/build.gradle
    script: | 
      #!/bin/sh
      set -ex
      printenv

Here is a list of the built-in environment variables with brief explanations:

Environment variableValue
ANDROID_SDK_ROOTAbsolute path to Android SDK and tools
CItrue
CONTINUOUS_INTEGRATIONtrue
BUILD_NUMBERNumber of the build for this project in Codemagic for the given workflow
PROJECT_BUILD_NUMBERNumber of the build for this project in Codemagic
FLUTTER_ROOTAbsolute path to Flutter SDK
CM_BRANCHThe current branch being built, for pull requests it is the source branch
CM_TAGThe tag being built if started from a tag webhook, unset otherwise
CM_REPO_SLUGThe slug of the repository that is currently being built in the form owner_name/repository_name. Unset for repositories added from custom source
CM_COMMITCommit hash that is currently being built by Codemagic, for pull request builds it is the hash of the source commit
CM_PREVIOUS_COMMITCommit hash of the previous successfully built commit in the same branch, (current excluded), unset if there is no previous successful commit
CM_PULL_REQUESTtrue, if the current build is building a pull request, false otherwise
CM_PULL_REQUEST_NUMBERSet to Integer ID of the pull request for the Git provider (Bitbucket, Github etc) if the current build is building a pull request, unset otherwise
CM_PULL_REQUEST_DESTThe destination branch, if the current build is building a pull request, unset otherwise
CM_CLONE_DEPTHNumber of commits to be cloned. Overwrites the following defaults: branch builds and destination branch for PR builds - 50, tag builds - 1
CM_CLONE_UNSHALLOWSet true to clone full commit history
CM_RECURSIVE_SUBMODULE_INITIf set to false, recursive submodule cloning is disabled
CM_PROJECT_IDUUID of the project that is being built
CM_BUILD_IDUUID of the build
CM_TEST_STEP_STATUSTest step status, success or failure
CM_BUILD_STEP_STATUSBuild step status, success, failure or skipped. Only available when using Workflow Editor, unavailable with codemagic.yaml
CM_BUILD_DIRAbsolute path to the root directory of the cloned repository in Codemagic builders
CM_BUILD_OUTPUT_DIRContains the artifact files generated during the build
CM_EXPORT_DIRThe files added to this directory will be added to a zip file and made available as build artifacts
CM_FLUTTER_SCHEMEName of the iOS scheme to be used
CM_KEYSTORE_PASSWORDPassword of Android keystore as configured in the UI
CM_KEY_PASSWORDPassword of Android key as configured in the UI
CM_KEY_ALIASAlias of the key as configured in the UI
CM_KEYSTORE_PATHPath of the file in our VM
CM_ARTIFACT_LINKSInformation about generated build artifacts that is available in post-publishing step. Read more about it below.
CM_WORKFLOW_NAMEName of the workflow that is currently being built
CM_ENVEnvironment file that sets/overrides environment variables at build time

$CM_ARTIFACT_LINKS environment variable value is a JSON encoded list in the following form:

[
  {
    "name": "Codemagic_Release.ipa",
    "type": "ipa",
    "url": "https://api.codemagic.io/artifacts/2e7564b2-9ffa-40c2-b9e0-8980436ac717/81c5a723-b162-488a-854e-3f5f7fdfb22f/Codemagic_Release.ipa",
    "md5": "d2884be6985dad3ffc4d6f85b3a3642a",
    "versionName": "1.0.2",
    "bundleId": "io.codemagic.app"
  }
]