Releasing CodePush updates with Bitrise CI
You can release your CodePush updates via a Bitrise CI Workflow. The process requires:
- Setting up CodePush credentials: create Environment Variables and a Secret that hold the app IDs, the deployment name, the target versions, and a Bitrise API token.
- Creating a Workflow that creates the update packages for both iOS and Android, and uploads both to Bitrise.
Configuring CodePush credentials on BitriseClick to copy link
-
Get your Release Management app IDs (how to find them) and the names of your CodePush deployments.
-
Create Environment Variables for the connected app IDs, the deployment name, and the target versions:
IOS_CONNECTED_APP_ID: The app ID for the iOS app.ANDROID_CONNECTED_APP_ID: The app ID for the Android app.CODEPUSH_DEPLOYMENT: The name of the deployment to release to, for exampleStaging.APP_TARGET_VERSIONS: The app versions that receive the update. Use an exact version or a range expression, for example1.2.0or>=1.5.0.
Deployments belong to an app, so the iOS and the Android app each have their own deployment. The two deployments can share a name, for example
Staging. In that case, setCODEPUSH_DEPLOYMENTtoStagingand Bitrise finds the right deployment for each app.Bitrise cannot check whether your update works with the native code of an app version. You decide which versions are compatible, so set
APP_TARGET_VERSIONSyourself before each release. -
Create a Secret called
BITRISE_API_TOKENthat holds your personal access token or workspace API token.
Creating a Workflow for CodePush updatesClick to copy link
This section shows you how to create a CI Workflow that will:
- Create an update package for iOS.
- Upload the iOS update package to Bitrise.
- Create an update package for Android.
- Upload the Android update package to Bitrise.
You can create these update packages and upload them with either the Bitrise CodePush Publish Step or the CodePush CLI. Both detect whether your project uses bare React Native or Expo, and each run handles one platform, so add it once for iOS and once for Android.
Using the Bitrise CodePush Publish StepClick to copy link
We recommend the Step for most projects. It installs your JavaScript dependencies, bundles your app, and uploads the update. Add it after the git-clone Step, once for each platform:
workflows:
codepush_update_deploy:
steps:
- git-clone@8: {}
- codepush-publish@1:
title: Publish iOS update
inputs:
- platform: ios
- app_id: $IOS_CONNECTED_APP_ID
- deployment: $CODEPUSH_DEPLOYMENT
- app_version: $APP_TARGET_VERSIONS
- api_token: $BITRISE_API_TOKEN
- codepush-publish@1:
title: Publish Android update
inputs:
- platform: android
- app_id: $ANDROID_CONNECTED_APP_ID
- deployment: $CODEPUSH_DEPLOYMENT
- app_version: $APP_TARGET_VERSIONS
- api_token: $BITRISE_API_TOKEN
The Step also has optional inputs such as rollout_percentage, mandatory, and description. It detects the entry file and the Hermes setting, and you can override them with entry_file and hermes. If an earlier Step already installs your dependencies, set skip_dependency_install to "true".
To sign your update, upload your private key as a Secret File and set private_key_path to its Environment Variable, for example $CODEPUSH_PRIVATE_KEY.
The Step exports the update package to $BITRISE_DEPLOY_DIR, so a later Deploy to Bitrise.io Step adds it to the build's artifacts.
Using the CodePush CLIClick to copy link
Use the CLI if you need more than publishing an update, for example to promote a release to another deployment or to roll one back. Install the CodePush CLI plugin, install your dependencies, and run push --bundle once for each platform. The command bundles your JavaScript and uploads the update. The CLI reads BITRISE_API_TOKEN from the environment automatically.
workflows:
codepush_update_deploy:
steps:
- git-clone@8: {}
- script@1:
title: Install the CodePush CLI
inputs:
- content: bitrise plugin install https://github.com/bitrise-io/bitrise-plugins-codepush-cli.git
- npm@1:
inputs:
- command: install
- script@1:
title: Push iOS update
inputs:
- content: |-
bitrise :codepush push --bundle --platform ios \
--app-id "$IOS_CONNECTED_APP_ID" \
--deployment "$CODEPUSH_DEPLOYMENT" \
--app-version "$APP_TARGET_VERSIONS"
- script@1:
title: Push Android update
inputs:
- content: |-
bitrise :codepush push --bundle --platform android \
--app-id "$ANDROID_CONNECTED_APP_ID" \
--deployment "$CODEPUSH_DEPLOYMENT" \
--app-version "$APP_TARGET_VERSIONS"
In a Bitrise build, the CLI attaches the build number and commit hash to the update. It also exports the update ID to the next Steps. For all commands and flags, see the CodePush CLI reference.
Automating the CodePush update releaseClick to copy link
After creating a Workflow to generate and upload your CodePush updates, you have two ways of running it:
- Run the Workflow manually.
- Triggering a build automatically when a defined condition is met. For the available conditions, see Supported trigger conditions.
You can set up several different types of triggers to automate the process. Our example configuration uses a pull request trigger with a label:
Release a CodePush update when a pull request gets a label
In this example, we're setting up a trigger where the codepush_update_deploy Workflow runs when any pull request receives the release-update label. Use it to release a pull request to a deployment, such as Staging, for testing before you merge.
-
Create the trigger: set up a pull request trigger with the
labelcondition set torelease-update. Thetarget_branchcondition defaults to*, so pull requests to any branch match. To limit releases to one branch, also settarget_branch.GUI configYou can set these up on the GUI of the Workflow Editor, too. Here we're showing you the YAML configuration.
format_version: "13"default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.gitproject_type: react-nativeworkflows:codepush_update_deploy:status_report_name: 'Executing <target_id> for <project_title>'description: |Uploads Update Bundle to Bitrisesteps:[...]triggers:pull_request:- label: release-update -
When you want to release a CodePush update, open a pull request.
-
After the pull request has been reviewed and approved, add the
release-updatelabel to it.
Bitrise runs the build when you add the label, before the pull request is merged. It releases the update from the code of the pull request.