github.com/nilium/gitlab-runner@v12.5.0+incompatible/docs/register/index.md (about) 1 # Registering Runners 2 3 Registering a Runner is the process that binds the Runner with a GitLab instance. 4 5 ## Requirements 6 7 Before registering a Runner, you need to first: 8 9 - [Install it](../install/index.md) on a server separate than where GitLab 10 is installed on 11 - [Obtain a token](https://docs.gitlab.com/ee/ci/runners/) for a shared or 12 specific Runner via GitLab's interface 13 14 ## GNU/Linux 15 16 To register a Runner under GNU/Linux: 17 18 1. Run the following command: 19 20 ```sh 21 sudo gitlab-runner register 22 ``` 23 24 1. Enter your GitLab instance URL: 25 26 ```text 27 Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com ) 28 https://gitlab.com 29 ``` 30 31 1. Enter the token you obtained to register the Runner: 32 33 ```text 34 Please enter the gitlab-ci token for this runner 35 xxx 36 ``` 37 38 1. Enter a description for the Runner, you can change this later in GitLab's 39 UI: 40 41 ```text 42 Please enter the gitlab-ci description for this runner 43 [hostname] my-runner 44 ``` 45 46 1. Enter the [tags associated with the Runner][tags], you can change this later in GitLab's UI: 47 48 ```text 49 Please enter the gitlab-ci tags for this runner (comma separated): 50 my-tag,another-tag 51 ``` 52 53 1. Enter the [Runner executor](../executors/README.md): 54 55 ```text 56 Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: 57 docker 58 ``` 59 60 1. If you chose Docker as your executor, you'll be asked for the default 61 image to be used for projects that do not define one in `.gitlab-ci.yml`: 62 63 ```text 64 Please enter the Docker image (eg. ruby:2.1): 65 alpine:latest 66 ``` 67 68 ## macOS 69 70 To register a Runner under macOS: 71 72 1. Run the following command: 73 74 ```sh 75 gitlab-runner register 76 ``` 77 78 1. Enter your GitLab instance URL: 79 80 ```text 81 Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com ) 82 https://gitlab.com 83 ``` 84 85 1. Enter the token you obtained to register the Runner: 86 87 ```text 88 Please enter the gitlab-ci token for this runner 89 xxx 90 ``` 91 92 1. Enter a description for the Runner, you can change this later in GitLab's 93 UI: 94 95 ```text 96 Please enter the gitlab-ci description for this runner 97 [hostname] my-runner 98 ``` 99 100 1. Enter the [tags associated with the Runner][tags], you can change this later in GitLab's UI: 101 102 ```text 103 Please enter the gitlab-ci tags for this runner (comma separated): 104 my-tag,another-tag 105 ``` 106 107 1. Enter the [Runner executor](../executors/README.md): 108 109 ```text 110 Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: 111 docker 112 ``` 113 114 1. If you chose Docker as your executor, you'll be asked for the default 115 image to be used for projects that do not define one in `.gitlab-ci.yml`: 116 117 ```text 118 Please enter the Docker image (eg. ruby:2.1): 119 alpine:latest 120 ``` 121 122 **Note** _[be sure Docker.app is installed on your mac](https://docs.docker.com/docker-for-mac/install/)_ 123 124 ## Windows 125 126 To register a Runner under Windows: 127 128 1. Run the following command: 129 130 ```sh 131 ./gitlab-runner.exe register 132 ``` 133 134 1. Enter your GitLab instance URL: 135 136 ```text 137 Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com ) 138 https://gitlab.com 139 ``` 140 141 1. Enter the token you obtained to register the Runner: 142 143 ```text 144 Please enter the gitlab-ci token for this runner 145 xxx 146 ``` 147 148 1. Enter a description for the Runner, you can change this later in GitLab's 149 UI: 150 151 ```text 152 Please enter the gitlab-ci description for this runner 153 [hostname] my-runner 154 ``` 155 156 1. Enter the [tags associated with the Runner][tags], you can change this later in GitLab's UI: 157 158 ```text 159 Please enter the gitlab-ci tags for this runner (comma separated): 160 my-tag,another-tag 161 ``` 162 163 1. Enter the [Runner executor](../executors/README.md): 164 165 ```text 166 Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: 167 docker 168 ``` 169 170 1. If you chose Docker as your executor, you'll be asked for the default 171 image to be used for projects that do not define one in `.gitlab-ci.yml`: 172 173 ```text 174 Please enter the Docker image (eg. ruby:2.1): 175 alpine:latest 176 ``` 177 178 If you'd like to register multiple Runners on the same machine with different 179 configurations repeat the `./gitlab-runner.exe register` command. 180 181 ## FreeBSD 182 183 To register a Runner under FreeBSD: 184 185 1. Run the following command: 186 187 ```sh 188 sudo -u gitlab-runner -H /usr/local/bin/gitlab-runner register 189 ``` 190 191 1. Enter your GitLab instance URL: 192 193 ```text 194 Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com ) 195 https://gitlab.com 196 ``` 197 198 1. Enter the token you obtained to register the Runner: 199 200 ```text 201 Please enter the gitlab-ci token for this runner 202 xxx 203 ``` 204 205 1. Enter a description for the Runner, you can change this later in GitLab's 206 UI: 207 208 ```text 209 Please enter the gitlab-ci description for this runner 210 [hostname] my-runner 211 ``` 212 213 1. Enter the [tags associated with the Runner][tags], you can change this later in GitLab's UI: 214 215 ```text 216 Please enter the gitlab-ci tags for this runner (comma separated): 217 my-tag,another-tag 218 ``` 219 220 1. Enter the [Runner executor](../executors/README.md): 221 222 ```text 223 Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: 224 docker 225 ``` 226 227 1. If you chose Docker as your executor, you'll be asked for the default 228 image to be used for projects that do not define one in `.gitlab-ci.yml`: 229 230 ```text 231 Please enter the Docker image (eg. ruby:2.1): 232 alpine:latest 233 ``` 234 235 ## Docker 236 237 These instructions are meant to be followed after [Run GitLab Runner in a container](../install/docker.md). 238 In this section, you will launch an ephemeral `gitlab-runner` container to 239 register the container that you created during install. After you finish 240 registration, the resulting configuration will be written to your chosen config 241 volume (e.g. `/srv/gitlab-runner/config`), and will be automatically loaded by 242 the runner using that config volume. 243 244 To register a Runner using a Docker container: 245 246 1. Run the register command: 247 248 ```sh 249 docker run --rm -t -i -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register 250 ``` 251 252 NOTE: **Note:** 253 If you used a config volume other than `/srv/gitlab-runner/config` during 254 install, then you should update the command with the correct volume. 255 256 1. Enter your GitLab instance URL: 257 258 ```text 259 Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com ) 260 https://gitlab.com 261 ``` 262 263 1. Enter the token you obtained to register the Runner: 264 265 ```text 266 Please enter the gitlab-ci token for this runner 267 xxx 268 ``` 269 270 1. Enter a description for the Runner, you can change this later in GitLab's 271 UI: 272 273 ```text 274 Please enter the gitlab-ci description for this runner 275 [hostname] my-runner 276 ``` 277 278 1. Enter the [tags associated with the Runner][tags], you can change this later in GitLab's UI: 279 280 ```text 281 Please enter the gitlab-ci tags for this runner (comma separated): 282 my-tag,another-tag 283 ``` 284 285 1. Enter the [Runner executor](../executors/README.md): 286 287 ```text 288 Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: 289 docker 290 ``` 291 292 1. If you chose Docker as your executor, you'll be asked for the default 293 image to be used for projects that do not define one in `.gitlab-ci.yml`: 294 295 ```text 296 Please enter the Docker image (eg. ruby:2.1): 297 alpine:latest 298 ``` 299 300 ## One-line registration command 301 302 If you want to use the non-interactive mode to register a Runner, you can 303 either use the `register` subcommands or use their equivalent environment 304 variables. 305 306 To see a list of all the `register` subcommands, use: 307 308 ```sh 309 gitlab-runner register -h 310 ``` 311 312 To register a Runner using the most common options, you would do: 313 314 ```sh 315 sudo gitlab-runner register \ 316 --non-interactive \ 317 --url "https://gitlab.com/" \ 318 --registration-token "PROJECT_REGISTRATION_TOKEN" \ 319 --executor "docker" \ 320 --docker-image alpine:latest \ 321 --description "docker-runner" \ 322 --tag-list "docker,aws" \ 323 --run-untagged="true" \ 324 --locked="false" \ 325 --access-level="not_protected" 326 ``` 327 328 If you're running the Runner in a Docker container, the `register` command would 329 look like: 330 331 ```sh 332 docker run --rm -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \ 333 --non-interactive \ 334 --executor "docker" \ 335 --docker-image alpine:latest \ 336 --url "https://gitlab.com/" \ 337 --registration-token "PROJECT_REGISTRATION_TOKEN" \ 338 --description "docker-runner" \ 339 --tag-list "docker,aws" \ 340 --run-untagged="true" \ 341 --locked="false" \ 342 --access-level="not_protected" 343 ``` 344 345 ## `[[runners]]` configuration template file 346 347 > [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/issues/4228) in GitLab Runner 12.2. 348 349 Some Runner configuration settings can't be set with environment variables or command line options. 350 351 For example: 352 353 - Environment variables do not support slices. 354 - Command line option support is internationally unavailable for the settings for the 355 whole Kubernetes executor volumes tree. 356 357 This is a problem for environments that are handled by any kind of automation, such as the 358 [GitLab Runner official Helm chart](../install/kubernetes.md). In cases like these, the only solution was 359 to manually update the `config.toml` file after the Runner was registered. This is less 360 than ideal, error-prone, and not reliable. Especially when more than one registration 361 for the same Runner installation is done. 362 363 This problem can be resolved with the usage of a _configuration template file_. 364 365 To use a configuration template file, pass a path to the file to `register` with either 366 the: 367 368 - `--template-config` command line option. 369 - `TEMPLATE_CONFIG_FILE` environment variable. 370 371 The configuration template file supports: 372 373 - Only a single 374 [`[[runners]]`](../configuration/advanced-configuration.md#the-runners-section) 375 section. 376 - No global options. 377 378 When `--template-config` or `TEMPLATE_CONFIG_FILE` is used, the configuration of `[[runners]]` entry 379 is merged into the configuration of newly created `[[runners]]` entry in the regular `config.toml` 380 file. 381 382 The merging is done only for options that were _empty_. That is: 383 384 - Empty strings. 385 - Nulls or/non existent entries. 386 - Zeroes. 387 388 With this: 389 390 - All configuration provided with command line options and/or environment variables during the 391 `register` command call take precedence. 392 - The template fills the gaps and adds additional settings. 393 394 ### Example 395 396 We register a Kubernetes-executor-based Runner to some test project and see what the 397 `config.toml` file looks like: 398 399 ```bash 400 $ sudo gitlab-runner register \ 401 --config /tmp/test-config.toml \ 402 --non-interactive \ 403 --url https://gitlab.com \ 404 --registration-token __REDACTED__ \ 405 --name test-runner \ 406 --tag-list kubernetes,test \ 407 --locked \ 408 --paused \ 409 --executor kubernetes \ 410 --kubernetes-host http://localhost:9876/ 411 412 Runtime platform arch=amd64 os=linux pid=1684 revision=88310882 version=11.10.0~beta.1251.g88310882 413 414 Registering runner... succeeded runner=__REDACTED__ 415 Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 416 ``` 417 418 The command above will create the following `config.toml` file: 419 420 ```toml 421 concurrent = 1 422 check_interval = 0 423 424 [session_server] 425 session_timeout = 1800 426 427 [[runners]] 428 name = "test-runner" 429 url = "https://gitlab.com" 430 token = "__REDACTED__" 431 executor = "kubernetes" 432 [runners.cache] 433 [runners.cache.s3] 434 [runners.cache.gcs] 435 [runners.kubernetes] 436 host = "http://localhost:9876/" 437 bearer_token_overwrite_allowed = false 438 image = "" 439 namespace = "" 440 namespace_overwrite_allowed = "" 441 privileged = false 442 service_account_overwrite_allowed = "" 443 pod_annotations_overwrite_allowed = "" 444 [runners.kubernetes.volumes] 445 ``` 446 447 We can see the basic configuration created from the provided command line options: 448 449 - Runner credentials (URL and token). 450 - The executor specified. 451 - The default, empty section `runners.kubernetes` with only the one option 452 provided during the registration filled out. 453 454 Normally one would need to set few more options to make the Kubernetes executor 455 usable, but the above is enough for the purpose of our example. 456 457 Let's now assume that we need to configure an `emptyDir` volume for our Kubernetes executor. There is 458 no way to add this while registering with neither environment variables nor command line options. 459 We would need to **manually append** something like this to the end of the file: 460 461 ```toml 462 [[runners.kubernetes.volumes.empty_dir]] 463 name = "empty_dir" 464 mount_path = "/path/to/empty_dir" 465 medium = "Memory" 466 ``` 467 468 Because [TOML](https://github.com/toml-lang/toml) doesn't require proper indentation (it 469 relies on entries ordering), we could just append the required changes to the end of the 470 file. 471 472 However, this becomes tricky when more `[[runners]]` sections are being registered 473 within one `config.toml` file. The assumption that the new one will be always at the 474 end is risky. 475 476 With GitLab Runner 12.2, this becomes much easier using the `--template-config` flag. 477 478 ```bash 479 $ cat > /tmp/test-config.template.toml << EOF 480 [[runners]] 481 [runners.kubernetes] 482 [runners.kubernetes.volumes] 483 [[runners.kubernetes.volumes.empty_dir]] 484 name = "empty_dir" 485 mount_path = "/path/to/empty_dir" 486 medium = "Memory" 487 EOF 488 ``` 489 490 Having the file, we can now try to register the Runner again, but this time adding the 491 `--template-config /tmp/test-config.template.toml` option. Apart from this change, the 492 rest of registration command will be exactly the same: 493 494 ```bash 495 $ sudo gitlab-runner register \ 496 --config /tmp/test-config.toml \ 497 --template-config /tmp/test-config.template.toml \ 498 --non-interactive \ 499 --url https://gitlab.com \ 500 --registration-token __REDACTED__ \ 501 --name test-runner \ 502 --tag-list kubernetes,test \ 503 --locked \ 504 --paused \ 505 --executor kubernetes \ 506 --kubernetes-host http://localhost:9876/ 507 508 Runtime platform arch=amd64 os=linux pid=8798 revision=88310882 version=11.10.0~beta.1251.g88310882 509 510 Registering runner... succeeded runner=__REDACTED__ 511 Merging configuration from template file 512 Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 513 ``` 514 515 As we can see, there is a little change in the output of the registration command. 516 We can see a `Merging configuration from template file` line. 517 518 Now let's see what the configuration file looks like after using the template: 519 520 ```toml 521 concurrent = 1 522 check_interval = 0 523 524 [session_server] 525 session_timeout = 1800 526 527 [[runners]] 528 name = "test-runner" 529 url = "https://gitlab.com" 530 token = "__REDACTED__" 531 executor = "kubernetes" 532 [runners.cache] 533 [runners.cache.s3] 534 [runners.cache.gcs] 535 [runners.kubernetes] 536 host = "http://localhost:9876/" 537 bearer_token_overwrite_allowed = false 538 image = "" 539 namespace = "" 540 namespace_overwrite_allowed = "" 541 privileged = false 542 service_account_overwrite_allowed = "" 543 pod_annotations_overwrite_allowed = "" 544 [runners.kubernetes.volumes] 545 546 [[runners.kubernetes.volumes.empty_dir]] 547 name = "empty_dir" 548 mount_path = "/path/to/empty_dir" 549 medium = "Memory" 550 ``` 551 552 We can see, that the configuration is almost the same as it was previously. The only 553 change is that it now has the `[[runners.kubernetes.volumes.empty_dir]]` entry with 554 its options at the end of the file. It's added to the `[[runners]]` entry that was 555 created by the registration. And because the whole file is saved with the same mechanism, 556 we also have proper indentation. 557 558 If the configuration template includes a settings, and the same setting is passed to the 559 `register` command, the one passed to the `register` command takes precedence over the one 560 specified inside of the config template. 561 562 ```bash 563 $ cat > /tmp/test-config.template.toml << EOF 564 [[runners]] 565 executor = "docker" 566 EOF 567 568 $ sudo gitlab-runner register \ 569 --config /tmp/test-config.toml \ 570 --template-config /tmp/test-config.template.toml \ 571 --non-interactive \ 572 --url https://gitlab.com \ 573 --registration-token __REDACTED__ \ 574 --name test-runner \ 575 --tag-list shell,test \ 576 --locked \ 577 --paused \ 578 --executor shell 579 580 Runtime platform arch=amd64 os=linux pid=12359 revision=88310882 version=11.10.0~beta.1251.g88310882 581 582 Registering runner... succeeded runner=__REDACTED__ 583 Merging configuration from template file 584 Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 585 ``` 586 587 As we can see, the registration command is specifying the `shell` executor, while the template 588 contains the `docker` one. Let's see what is the final configuration content: 589 590 ```toml 591 concurrent = 1 592 check_interval = 0 593 594 [session_server] 595 session_timeout = 1800 596 597 [[runners]] 598 name = "test-runner" 599 url = "https://gitlab.com" 600 token = "__REDACTED__" 601 executor = "shell" 602 [runners.cache] 603 [runners.cache.s3] 604 [runners.cache.gcs] 605 ``` 606 607 The configuration set with the `register` command options took priority and was 608 chosen to be placed in the final config. 609 610 [tags]: https://docs.gitlab.com/ee/ci/runners/#using-tags