Using the CodePush plugin
Initialize and run a CodePush project after successfully installing the CodePush CLI plugin.
Initializing a CodePush project
After successfully installing the CodePush plugin, and setting up authentication, you can start a new project via the Bitrise CLI. To start the project, run the following command:
bitrise :codepush init
The command creates a .codepush.json file in the current directory. This file stores your app ID. You can commit it to version control so your team shares the same configuration.
When running the init command for the first time, the CLI will prompt you for the app ID. You can get it from the URL of the app in Release Management: https://app.bitrise.io/release-management/workspaces/<workspace-slug>/connected-apps/<app-id>/, or via the API.
Enter your app ID (UUID): >a3f47d2c-6b9e-4f1a-9d2b-7c8e5a1b2c3d
Alternatively, you can pass the ID with the --app-id flag. This is a global setting so if you use it, you will no longer be prompted for an app ID when running the init command in the same directory:
bitrise :codepush init --app-id a3f47d2c-6b9e-4f1a-9d2b-7c8e5a1b2c3d
Another option is to set the $CODEPUSH_APP_ID Environment Variable. If the app ID is available from more than one source, the plugin resolves them in the following order:
-
--app-idflag (highest priority) -
$CODEPUSH_APP_IDenvironment variable -
codepush.jsonfile in the current directory
You can overwrite an existing .codepush.json file with the --force flag:
bitrise :codepush init --force --app-id a3f47d2c-6b9e-4f1a-9d2b-7c8e5a1b2c3d
Bundling and pushing your updates
To update your app via CodePush, you need to create an update bundle and then push it to the Codepush server. The CodePush CLI plugin has two commands for this purpose:
-
codepush bundle: Generates JavaScript bundles for React Native and Expo projects. It auto-detects the project type, entry file, Hermes configuration, and Metro config. -
codepush push: Pushes the pre-built bundle to devices. You need to specify the app version and the deployment name or ID.
Bundle your app for each platform separately:
codepush bundle --platform ios codepush bundle --platform android
Push a pre-built bundle. Replace the APP_UUID with your app's UUID which you can get from the app URL in Release Management:
codepush push ./codepush-bundle \ --app-id <APP_UUID> --deployment Staging --app-version 1.0.0
You can also bundle and push the app in one step:
codepush push --bundle --platform ios \ --app-id <APP_UUID> --deployment Staging --app-version 1.0.0
Promoting and patching
You can update existing CodePush releases with the CLI, using two commands:
-
promote: Copy a release from one deployment to another. It is most commonly used to move a release from staging environment to production. -
patch: Update metadata on an existing release without re-deploying the code.
Move a release from staging to production while overriding metadata:
codepush promote \ --source-deployment Staging \ --destination-deployment Production \ --app-id <APP_UUID> \ --rollout 25 --description "Gradual rollout"
Pass --no-duplicate-release-error to exit 0 with a warning instead of an error when the target deployment already contains a release with identical content.
Patch a specific release:
codepush patch --deployment Production --label v5 --mandatory true --app-id <APP_UUID>
Increase rollout on the latest release:
codepush patch --deployment Production --rollout 50 --app-id <APP_UUID>
Rollback
You can create a new release that mirrors a previous version with the rollback command.
Rollback to the immediately previous release:
codepush rollback --deployment Production --app-id <APP_UUID>
Rollback to a specific release
codepush rollback --deployment Production --target-release v3 --app-id <APP_UUID>
Managing CodePush deployments
Create a CodePush deployment to get your deployment key. You need the deployment key to release CodePush updates to your apps.
The CLI plugin also allows you to list deployments, view their details and release history. You can also clear all releases from a deployment.
List all deployments:
codepush deployment list --app-id <APP_UUID> codepush deployment list --display-keys --app-id <APP_UUID>
Create a new deployment with the deployment add command. You need to set a name and provide the app ID:
codepush deployment add Beta --app-id <APP_UUID>
Create a new deployment with an existing, custom deployment key:
codepush deployment add Beta --key my-custom-key --app-id <APP_UUID>
View deployment details and the latest release with deployment info. You must provide a deployment name and the app ID.
codepush deployment info Staging --app-id <APP_UUID>
View release history with the deployment history command. By default, it shows the last 10 releases but you can use the --limit flag to modify that value.
codepush deployment history Staging --app-id <APP_UUID> codepush deployment history Staging --limit 25 --app-id <APP_UUID>
You can also query the author of the releases:
codepush deployment history Staging --display-author --app-id <APP_UUID>
Rename a deployment with the deployment rename command. You must set the OldName and NewName attributes:
codepush deployment rename OldName --name NewName --app-id <APP_UUID>
Clear all releases from a deployment with deployment clear. It's a destructive operation that requires the --yes flag in a CI setting.
codepush deployment clear Staging --app-id <APP_UUID> --yes
Delete a deployment with the deployment remove command. It's a destructive operation that requires the --yes flag in a CI setting.
codepush deployment remove Beta --app-id <APP_UUID> --yes
Managing CodePush updates
Use the CodePush CLI plugin to manage updates for your app. You can view update details, check processing status, and remove updates.
View details of the latest update with the update info command:
codepush update info Staging --app-id <APP_UUID>
View a specific update by label with the --label flag:
codepush update info Staging --label v5 --app-id <APP_UUID>
Check the processing status of an update with the update status command. This is useful after a push:
codepush update status Staging --app-id <APP_UUID>
Delete a specific update with the update remove command. Use the --label flag to specify the update and --yes to confirm the deletion:
codepush update remove Staging --label v3 --app-id <APP_UUID> --yes