1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
---
stage: Verify
group: Runner
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
---
# Set up macOS runners
To run a CI/CD job on a macOS runner, complete the following steps in order.
When you're done, GitLab Runner will be running on a macOS machine
and an individual runner will be ready to process jobs.
- Change the system shell to Bash.
- Install Homebrew, rbenv, and GitLab Runner.
- Configure rbenv and install Ruby.
- Install Xcode.
- Register a runner.
- Configure CI/CD.
## Prerequisites
Before you begin:
- Install a recent version of macOS. This guide was developed on 11.4.
- Ensure you have terminal or SSH access to the machine.
## Change the system shell to Bash
Newer versions of macOS ship with Zsh as the default shell.
You must change it to Bash.
1. Connect to your machine and determine the default shell:
```shell
echo $shell
```
1. If the result is not `/bin/bash`, change the shell by running:
```shell
chsh -s /bin/bash
```
1. Enter your password.
1. Restart your terminal or reconnect by using SSH.
1. Run `echo $SHELL` again. The result should be `/bin/bash`.
## Install Homebrew, rbenv, and GitLab Runner
The runner needs certain environment options to connect to the machine and run a job.
1. Install the [Homebrew package manager](https://brew.sh/):
```shell
/bin/bash -c "$(curl "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh")"
```
1. Set up [`rbenv`](https://github.com/rbenv/rbenv), which is a Ruby version manager, and GitLab Runner:
```shell
brew install rbenv gitlab-runner
brew services start gitlab-runner
```
## Configure rbenv and install Ruby
Now configure rbenv and install Ruby.
1. Add rbenv to the Bash environment:
```shell
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile
```
1. Install Ruby 2.74 and set it as the machine's global default:
```shell
rbenv install 2.7.4
rbenv global 2.7.4
```
## Install Xcode
Now install and configure Xcode.
1. Go to one of these locations and install Xcode:
- The Apple App Store.
- The [Apple Developer Portal](https://developer.apple.com/download/all/?q=xcode).
- [`xcode-install`](https://github.com/xcpretty/xcode-install). This project aims to make it easier to download various
Apple dependencies from the command line.
1. Agree to the license and install the recommended additional components.
You can do this by opening Xcode and following the prompts, or by running the following command in the terminal:
```shell
sudo xcodebuild -runFirstLaunch
```
1. Update the active developer directory so that Xcode loads the proper command line tools during your build:
```shell
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
```
### Register a runner
Now register a runner to start picking up your CI/CD jobs.
1. In GitLab, on the top bar, select **Menu > Projects** or **Menu > Group** to find your project or group.
1. On the left sidebar, select **Settings > CI/CD**.
1. Expand **Runners**.
1. Note the URL and registration token.
1. In a terminal, start the interactive setup:
```shell
gitlab-runner register
```
1. Enter the GitLab URL.
1. Enter the registration token.
1. Enter a description for the runner.
You will use the description to identify the runner in GitLab, and the name is associated with jobs executed on this instance.
1. Enter tags, which direct specific jobs to specific instances. You will use these tags later to ensure macOS jobs
run on this macOS machine. In this example, enter:
```shell
macos
```
1. Type `shell` to select the shell [executor](../executors/index.md).
A success message is displayed:
```shell
> Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
```
To view the runner, go to **Settings > CI/CD** and expand **Runners**.
### Configure CI/CD
In your GitLab project, configure CI/CD and start a build. You can use this sample `.gitlab-ci.yml` file.
Notice the tags match the tags you used to register the runner.
```yaml
stages:
- build
- test
variables:
LANG: "en_US.UTF-8"
before_script:
- gem install bundler
- bundle install
- gem install cocoapods
- pod install
build:
stage: build
script:
- bundle exec fastlane build
tags:
- macos
test:
stage: test
script:
- bundle exec fastlane test
tags:
- macos
```
The macOS runner should now build your project.
|