Notes

Deploy to separate Expo release channels based on Bitbucket feature branches

Edit on GitHub


DevOps
2 minutes

What i need is to test multiple feature branches at the same time by deploying it to Expo. And i can’t be bothered with doing that manually.

  • $BITBUCKET_BRANCH is available, but it can not be used in custom pipelines (triggered from a commit) or used against tags. If you use it under the branches: block, it’ll fail, because those are run on commits.
  • You can only use it in a step that is manually triggered, inside a custom pipeline. Otherwise $BITBUCKET_BRANCH is not set. It outputs nothing in default: pipeline or branches: pipelines
  • First step in a pipeline can not be manually triggered
  • A trigger can only be executed if the previous step has successfully completed
  • If you use git-flow and have / in branch names (e.g. feature/profile), it will fail to work. Because Release channel name can only contain lowercase letters, numbers and special characters . _ and -

Here’s working code

 1# This is the build configuration for React Native Expo project using Bitbucket Pipelines.
 2# Configuration options: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
 3# Only use spaces to indent your .yml configuration.
 4# -----
 5# You can specify a custom docker image from Docker Hub as your build environment.
 6---
 7image: node:latest
 8
 9definitions:
10  caches: # configure caches to speed up builds. more: https://confluence.atlassian.com/bitbucket/caching-dependencies-895552876.html
11    npm: ~/.npm
12
13pipelines: # contains all your pipeline definitions. you can define multiple pipelines in the configuration file
14
15  custom:
16    Deploy to Expo:
17        - step:
18            name: Getting started
19            script:
20              - echo "--- Added this step just so i could manually trigger the next step (first step can not be manual) ---"
21              - echo "--- Run the next step in Pipeline! ---"
22        - step:
23            name: Deploy to Expo
24            trigger: manual
25            deployment: feature
26            caches:
27              - npm
28            script:
29              - unset NPM_CONFIG_USER
30              - npm ci
31              - npm i -g --unsafe-perm expo-cli
32              - echo -e "Deploying ${BITBUCKET_BRANCH}" to Expo
33              - expo login -u ${EXPO_USERNAME} -p ${EXPO_PASSWORD} # Use variables defined in Repository Settings
34              - expo publish --non-interactive --clear --release-channel ${BITBUCKET_BRANCH}
35              # WOULDN'T WORK if you have of / in branch name (e.g. feature/profile. if using gitflow there'll always be a /)
36              # Maybe use regex to replace it?