Trigger Expo Build GitLab CI - Snippet
Tags: expo, gitlab, reactnative, cicd
Published: 2024-02-29 15:39:56

Here is a snippet I use to trigger my apps to build. I have them set to manual because it costs money with Expo.

`.gitlab-ci.yml` snippet
```
eas_build_internal_android_developv2:
  stage: build-mobile
  image: node:16.17.0

  script:
    - npm install -g expo-cli
    - npm install -g eas-cli
    - cd mobileapp
    - npm i
    - EXPO_TOKEN=$EXPO_EAS_TOKEN eas build -p android --profile develop --no-wait

  only:
    refs:
      - develop
    changes:
      - mobileapp/**/* 
  when: manual

eas_build_internal_android_productionv2:
  stage: build-mobile
  image: node:16.17.0

  script:
    - npm install -g expo-cli
    - npm install -g eas-cli
    - cd mobileapp
    - npm i
    - EXPO_TOKEN=$EXPO_EAS_TOKEN eas build -p android --profile production --no-wait
  only:
    refs:
      - main
    changes:
      - mobileapp/**/* 
  when: manual

```

`eas.json
`
```
{
  "cli": {
    "version": ">= 2.2.1"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "env": {
        "EXPO_PUBLIC_BACKEND_DOMAIN": "https://something.ngrok-free.app"
      },
      "channel": "local",
      "distribution": "internal",
      "android": {
        "buildType": "apk"
      }
    },
    "develop": {
      "channel": "develop",
      "env": {
        "EXPO_PUBLIC_BACKEND_DOMAIN": "https://apidev.something.com",
        "EXPO_PUBLIC_GROWTHBOOK_CLIENT_KEY": ""
      },
      "distribution": "internal",
      "android": {
        "buildType": "apk"
      }
    },
    "production": {
      "env": {
        "EXPO_PUBLIC_BACKEND_DOMAIN": "https://api.something.com",
        "EXPO_PUBLIC_GROWTHBOOK_CLIENT_KEY": ""
      },
      "channel": "main",
      "distribution": "internal",
      "android": {
        "buildType": "apk"
      }
    }
  },
  "submit": {
    "production": {}
  }
}

```

## Might be also helpfull

`app.json
`


```

{
  "expo": {
    "name": "mobileapp",
    "slug": "mobileapp",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/something.png",
    "userInterfaceStyle": "light",
    "splash": {
      "image": "./assets/splash_v2.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/splash_v2.png",
        "backgroundColor": "#ffffff"
      },
      "package": "com.something.someone"
    },
    "web": {
      "favicon": "./assets/something.png"
    },
    "plugins": ["expo-router"],

    "extra": {
      "router": {
        "origin": false
      },
      "eas": {
        "projectId": "something"
      }
    },
    "runtimeVersion": {
      "policy": "appVersion"
    },
    "updates": {
      "url": "https://u.expo.dev/something"
    }
  }
}

```

`babel.config.js`

```
module.exports = function (api) {
  api.cache(true);
  return {
    presets: ["babel-preset-expo"],
    plugins: [
      [
        "module:react-native-dotenv",
        {
          moduleName: "@env",
          path: ".env",
          blacklist: null,
          whitelist: null,
          safe: false,
          allowUndefined: true,
        },
      ],
    ],
  };
};

```