|
| 1 | +# Codemagic Integration |
| 2 | + |
| 3 | +[Codemagic](https://codemagic.io/) is a cloud-based CI/CD tool for mobile applications that you can use for continuous integration and delivery together with *fastlane*. Codemagic has *fastlane* pre-installed, so you can easily run your *fastlane* scripts as part of the Codemagic build process. You only need a Fastfile in your repository to get started. You can find the version of pre-installed *fastlane* based on build machine type from [here](https://docs.codemagic.io/specs/machine-type/). |
| 4 | + |
| 5 | +## Getting started |
| 6 | + |
| 7 | +For publishing iOS apps, it is recommended to create an App Store Connect API key so you don't have to use 2FA. This also offers better performance and increased reliability. More details can be found [here](https://docs.fastlane.tools/app-store-connect-api/). |
| 8 | + |
| 9 | +## Adding environment variables |
| 10 | + |
| 11 | +The following **environment variables** need to be added to your workflow for *fastlane* integration. |
| 12 | + |
| 13 | +- `MATCH_PASSWORD` - the password used to encrypt/decrypt the repository used to store your distrbution certificates and provisioning profiles. |
| 14 | +- `MATCH_KEYCHAIN` - an arbitrary name to use for the keychain on the Codemagic build server, e.g "fastlane_keychain" |
| 15 | +- `MATCH_SSH_KEY` - an SSH private key used for cloning the Match repository that contains your distrbution certificates and provisioning profiles. The public key should be added to your Github account. See [here](https://docs.codemagic.io/configuration/access-private-git-submodules/) for more information about accessing Git dependencies with SSH keys. |
| 16 | +- `APP_STORE_CONNECT_PRIVATE_KEY` - the App Store Connect API key. Copy the entire contents of the .p8 file and paste into the environment variable value field. |
| 17 | +- `APP_STORE_CONNECT_KEY_IDENTIFIER` - the key identifier of your App Store Connect API key. |
| 18 | +- `APP_STORE_CONNECT_ISSUER_ID` - the issuer of your App Store Connect API key. |
| 19 | + |
| 20 | +Environment variables can be added in the Codemagic web app using the 'Environment variables' tab. Save all the variables to the same variable group and make sure that the **secure** checkbox is checked to encrypt any senstive values such as API keys or passwords. |
| 21 | + |
| 22 | +You can then import your variable group into your `codemagic.yaml`. For example, if you named your variable group 'fastlane', the group should be imported as follows: |
| 23 | + |
| 24 | +```yaml |
| 25 | +workflows: |
| 26 | + workflow-name: |
| 27 | + environment: |
| 28 | + groups: |
| 29 | + - fastlane |
| 30 | +``` |
| 31 | +
|
| 32 | +## Executing *fastlane* in your workflow |
| 33 | +
|
| 34 | +It is recommended to run your *fastlane* lanes using the `codemagic.yaml` configuration file. |
| 35 | + |
| 36 | +You should install your depenpendencies with `bundle install` and then execute the *fastlane* lane with `bundle exec fastlane <lane_name>` as follows: |
| 37 | + |
| 38 | +```yaml |
| 39 | +scripts: |
| 40 | + - bundle install |
| 41 | + - bundle exec fastlane beta |
| 42 | +``` |
| 43 | + |
| 44 | +If you need to use a specific version of bundler as defined in the `Gemfile.lock` file, you should install it with `gem install bundler:<version>` as follows: |
| 45 | + |
| 46 | +```yaml |
| 47 | +scripts: |
| 48 | + - gem install bundler:2.2.27 |
| 49 | + - bundle install |
| 50 | + - bundle exec fastlane beta |
| 51 | +``` |
| 52 | + |
| 53 | +## CocoaPods |
| 54 | + |
| 55 | +If you are using dependencies from Cocoapods, it might be necessary to include the CocoaPods gem in your Gemfile to prevent scope conflict issues. |
| 56 | + |
| 57 | +``` |
| 58 | +gem "fastlane" |
| 59 | +gem "cocoapods" |
| 60 | +``` |
| 61 | +
|
| 62 | +## Starting your build |
| 63 | +
|
| 64 | +You can start your build manually from within the Codemagic web app, or configure your builds to start on events such as pushing to your repository, creating or updating a pull request, adding a new tag, or even monitoring for file system changes. See more info in [Codemagic docs](https://docs.codemagic.io/). |
0 commit comments