github.com/secure-build/gitlab-runner@v12.5.0+incompatible/docs/commands/README.md (about) 1 # GitLab Runner commands 2 3 GitLab Runner contains a set of commands with which you register, manage and 4 run your builds. 5 6 You can check a recent list of commands by executing: 7 8 ```bash 9 gitlab-runner --help 10 ``` 11 12 Append `--help` after a command to see its specific help page: 13 14 ```bash 15 gitlab-runner <command> --help 16 ``` 17 18 ## Using environment variables 19 20 Most of the commands support environment variables as a method to pass the 21 configuration to the command. 22 23 You can see the name of the environment variable when invoking `--help` for a 24 specific command. For example, you can see below the help message for the `run` 25 command: 26 27 ```bash 28 gitlab-runner run --help 29 ``` 30 31 The output would be similar to: 32 33 ```bash 34 NAME: 35 gitlab-runner run - run multi runner service 36 37 USAGE: 38 gitlab-runner run [command options] [arguments...] 39 40 OPTIONS: 41 -c, --config "/Users/ayufan/.gitlab-runner/config.toml" Config file [$CONFIG_FILE] 42 ``` 43 44 ## Running in debug mode 45 46 Debug mode is especially useful when looking for the cause of some undefined 47 behavior or error. 48 49 To run a command in debug mode, prepend the command with `--debug`: 50 51 ```bash 52 gitlab-runner --debug <command> 53 ``` 54 55 ## Super-user permission 56 57 Commands that access the configuration of GitLab Runner behave differently when 58 executed as super-user (`root`). The file location depends on the user executing 59 the command. 60 61 Be aware of the notice that is written when executing the commands that are 62 used for running builds, registering services or managing registered runners: 63 64 ```bash 65 gitlab-runner run 66 67 INFO[0000] Starting multi-runner from /Users/ayufan/.gitlab-runner/config.toml ... builds=0 68 WARN[0000] Running in user-mode. 69 WARN[0000] Use sudo for system-mode: 70 WARN[0000] $ sudo gitlab-runner... 71 ``` 72 73 You should use `user-mode` if you are really sure that this is a mode that you 74 want to work with. Otherwise, prefix your command with `sudo`: 75 76 ``` 77 sudo gitlab-runner run 78 79 INFO[0000] Starting multi-runner from /etc/gitlab-runner/config.toml ... builds=0 80 INFO[0000] Running in system-mode. 81 ``` 82 83 In the case of **Windows** you may need to run the **Command Prompt** in 84 **Administrative Mode**. 85 86 ## Configuration file 87 88 GitLab Runner configuration uses the [TOML] format. 89 90 The file to be edited can be found in: 91 92 1. `/etc/gitlab-runner/config.toml` on \*nix systems when GitLab Runner is 93 executed as super-user (`root`) 94 1. `~/.gitlab-runner/config.toml` on \*nix systems when GitLab Runner is 95 executed as non-root 96 1. `./config.toml` on other systems 97 98 Most of the commands accept an argument to specify a custom configuration file, 99 allowing you to have a multiple different configurations on a single machine. 100 To specify a custom configuration file use the `-c` or `--config` flag, or use 101 the `CONFIG_FILE` environment variable. 102 103 [TOML]: https://github.com/toml-lang/toml 104 105 ## Signals 106 107 It is possible to use system signals to interact with GitLab Runner. The 108 following commands support the following signals: 109 110 | Command | Signal | Action | 111 |---------|--------|--------| 112 | `register` | **SIGINT** | Cancel runner registration and delete if it was already registered | 113 | `run`, `exec`, `run-single` | **SIGINT**, **SIGTERM** | Abort all running builds and exit as soon as possible. Use twice to exit now (**forceful shutdown**). | 114 | `run`, `exec`, `run-single` | **SIGQUIT** | Stop accepting a new builds. Exit as soon as currently running builds do finish (**graceful shutdown**). | 115 | `run` | **SIGHUP** | Force to reload configuration file | 116 117 For example, to force a reload of the Runner's configuration file, run 118 (all `gitlab-runner` processes will receive this signal): 119 120 ```bash 121 sudo killall -SIGHUP gitlab-runner 122 ``` 123 124 If your operating system is configured to automatically restart the service if it fails (which is the default on some platforms) it may automatically restart the runner if it's shut down by the signals above. 125 126 ## Commands overview 127 128 This is what you see if you run `gitlab-runner` without any arguments: 129 130 ```bash 131 NAME: 132 gitlab-runner - a GitLab Runner 133 134 USAGE: 135 gitlab-runner [global options] command [command options] [arguments...] 136 137 VERSION: 138 1.0.0~beta.142.ga8d37f3 (a8d37f3) 139 140 AUTHOR(S): 141 GitLab Inc. <support@gitlab.com> 142 143 COMMANDS: 144 exec execute a build locally 145 run run multi runner service 146 register register a new runner 147 install install service 148 uninstall uninstall service 149 start start service 150 stop stop service 151 restart restart service 152 status get status of a service 153 run-single start single runner 154 unregister unregister specific runner 155 verify verify all registered runners 156 archive find and archive files (internal) 157 artifacts upload build artifacts (internal) 158 extract extract files from an archive (internal) 159 help, h Shows a list of commands or help for one command 160 ``` 161 162 Below we will explain what each command does in detail. 163 164 ## Registration-related commands 165 166 The following commands allow you to register a new runner, or list and verify 167 them if they are still registered. 168 169 - [`gitlab-runner register`](#gitlab-runner-register) 170 - [Interactive registration](#interactive-registration) 171 - [Non-interactive registration](#non-interactive-registration) 172 - [`gitlab-runner list`](#gitlab-runner-list) 173 - [`gitlab-runner verify`](#gitlab-runner-verify) 174 - [`gitlab-runner unregister`](#gitlab-runner-unregister) 175 176 The above commands support the following arguments: 177 178 | Parameter | Default | Description | 179 |-------------|---------|-------------| 180 | `--config` | See the [configuration file section](#configuration-file) | Specify a custom configuration file to be used | 181 182 ### `gitlab-runner register` 183 184 This command registers your GitLab Runner in GitLab using the GitLab [Runners API](https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner). 185 186 The registered runner is 187 added to the [configuration file](#configuration-file). 188 You can use multiple configurations in a single GitLab Runner. Executing 189 `gitlab-runner register` adds a new configuration entry, it doesn't remove the 190 previous ones. 191 192 There are two options to register a Runner: 193 194 - interactive. 195 - non-interactive. 196 197 NOTE: **Note:** 198 Runners can be registered directly using the GitLab [Runners API](https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner) but 199 configuration will not be generated automatically. 200 201 #### Interactive registration 202 203 This command is usually used in interactive mode (**default**). You will be 204 asked multiple questions during a Runner's registration. 205 206 This question can be pre-filled by adding arguments when invoking the registration command: 207 208 ``` 209 gitlab-runner register --name my-runner --url http://gitlab.example.com --registration-token my-registration-token 210 ``` 211 212 Or by configuring the environment variable before the `register` command: 213 214 ``` 215 export CI_SERVER_URL=http://gitlab.example.com 216 export RUNNER_NAME=my-runner 217 export REGISTRATION_TOKEN=my-registration-token 218 export REGISTER_NON_INTERACTIVE=true 219 gitlab-runner register 220 ``` 221 222 To check all possible arguments and environments execute: 223 224 ``` 225 gitlab-runner register --help 226 ``` 227 228 #### Non-interactive registration 229 230 It's possible to use registration in non-interactive / unattended mode. 231 232 You can specify the arguments when invoking the registration command: 233 234 ``` 235 gitlab-runner register --non-interactive <other-arguments> 236 ``` 237 238 Or by configuring the environment variable before the `register` command: 239 240 ``` 241 <other-environment-variables> 242 export REGISTER_NON_INTERACTIVE=true 243 gitlab-runner register 244 ``` 245 246 > **Note:** Boolean parameters must be passed in the command line with `--key={true|false}`. 247 248 #### `[[runners]]` configuration template file 249 250 > [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/issues/4228) in GitLab Runner 12.2. 251 252 Additional options can be easily configured during Runner registration using the 253 [configuration template file](../register/index.md#runners-configuration-template-file) feature. 254 255 ### `gitlab-runner list` 256 257 This command lists all runners saved in the 258 [configuration file](#configuration-file). 259 260 ### `gitlab-runner verify` 261 262 This command checks if the registered runners can connect to GitLab, but it 263 doesn't verify if the runners are being used by the GitLab Runner service. An 264 example output is: 265 266 ```bash 267 Verifying runner... is alive runner=fee9938e 268 Verifying runner... is alive runner=0db52b31 269 Verifying runner... is alive runner=826f687f 270 Verifying runner... is alive runner=32773c0f 271 ``` 272 273 To delete the old and removed from GitLab runners, execute the following 274 command. 275 276 >**Warning:** 277 This operation cannot be undone, it will update the configuration file, so 278 make sure to have a backup of `config.toml` before executing it. 279 280 ```bash 281 gitlab-runner verify --delete 282 ``` 283 284 ### `gitlab-runner unregister` 285 286 This command unregisters registered runners using the GitLab [Runners API](https://docs.gitlab.com/ee/api/runners.html#delete-a-registered-runner). 287 288 It expects either: 289 290 - A full URL and the runner's token. 291 - The runner's name. 292 293 With the `--all-runners` option, it will unregister all the attached runners. 294 295 NOTE: **Note:** 296 Runners can be unregistered directly using the GitLab [Runners API](https://docs.gitlab.com/ee/api/runners.html#delete-a-registered-runner) but 297 configuration will not be modified for the user. 298 299 To unregister a specific runner, first get the runner's details by executing 300 `gitlab-runner list`: 301 302 ```bash 303 test-runner Executor=shell Token=t0k3n URL=http://gitlab.example.com 304 ``` 305 306 Then use this information to unregister it, using one of the following commands. 307 308 >**Warning:** 309 This operation cannot be undone, it will update the configuration file, so 310 make sure to have a backup of `config.toml` before executing it. 311 312 #### By URL and token 313 314 ```bash 315 gitlab-runner unregister --url http://gitlab.example.com/ --token t0k3n 316 ``` 317 318 #### By name 319 320 > **Note:** If there is more than one runner with the given name, only the first one will be removed 321 322 ```bash 323 gitlab-runner unregister --name test-runner 324 ``` 325 326 #### All Runners 327 328 ```bash 329 gitlab-runner unregister --all-runners 330 ``` 331 332 ## Service-related commands 333 334 > **Note:** Starting with GitLab Runner 10.0, service-related commands are **deprecated** 335 and will be removed in one of the upcoming releases. 336 337 The following commands allow you to manage the runner as a system or user 338 service. Use them to install, uninstall, start and stop the runner service. 339 340 - [`gitlab-runner install`](#gitlab-runner-install) 341 - [`gitlab-runner uninstall`](#gitlab-runner-uninstall) 342 - [`gitlab-runner start`](#gitlab-runner-start) 343 - [`gitlab-runner stop`](#gitlab-runner-stop) 344 - [`gitlab-runner restart`](#gitlab-runner-restart) 345 - [`gitlab-runner status`](#gitlab-runner-status) 346 - [Multiple services](#multiple-services) 347 - [**Access Denied** when running the service-related commands](#access-denied-when-running-the-service-related-commands) 348 349 All service related commands accept these arguments: 350 351 | Parameter | Default | Description | 352 |-------------|---------------------------------------------------|-------------| 353 | `--service` | `gitlab-runner` | Specify custom service name | 354 | `--config` | See the [configuration file](#configuration-file) | Specify a custom configuration file to use | 355 356 ### `gitlab-runner install` 357 358 This command installs GitLab Runner as a service. It accepts different sets of 359 arguments depending on which system it's run on. 360 361 When run on **Windows** or as super-user, it accepts the `--user` flag which 362 allows you to drop privileges of builds run with the **shell** executor. 363 364 | Parameter | Default | Description | 365 |-----------------------|-----------------------|-------------| 366 | `--service` | `gitlab-runner` | Specify service name to use | 367 | `--config` | See the [configuration file](#configuration-file) | Specify a custom configuration file to use | 368 | `--syslog` | `true` | Specify if the service should integrate with system logging service | 369 | `--working-directory` | the current directory | Specify the root directory where all data will be stored when builds will be run with the **shell** executor | 370 | `--user` | `root` | Specify the user which will be used to execute builds | 371 | `--password` | none | Specify the password for the user that will be used to execute the builds | 372 373 ### `gitlab-runner uninstall` 374 375 This command stops and uninstalls the GitLab Runner from being run as an 376 service. 377 378 ### `gitlab-runner start` 379 380 This command starts the GitLab Runner service. 381 382 ### `gitlab-runner stop` 383 384 This command stops the GitLab Runner service. 385 386 ### `gitlab-runner restart` 387 388 This command stops and then starts the GitLab Runner service. 389 390 ### `gitlab-runner status` 391 392 This command prints the status of the GitLab Runner service. The exit code is zero when the service is running and non-zero when the service is not running. 393 394 ### Multiple services 395 396 By specifying the `--service` flag, it is possible to have multiple GitLab 397 Runner services installed, with multiple separate configurations. 398 399 ## Run-related commands 400 401 This command allows to fetch and process builds from GitLab. 402 403 ### `gitlab-runner run` 404 405 This is main command that is executed when GitLab Runner is started as a 406 service. It reads all defined Runners from `config.toml` and tries to run all 407 of them. 408 409 The command is executed and works until it [receives a signal](#signals). 410 411 It accepts the following parameters. 412 413 | Parameter | Default | Description | 414 |-----------|---------|-------------| 415 | `--config` | See [#configuration-file](#configuration-file) | Specify a custom configuration file to be used | 416 | `--working-directory` | the current directory | Specify the root directory where all data will be stored when builds will be run with the **shell** executor | 417 | `--user` | the current user | Specify the user that will be used to execute builds | 418 | `--syslog` | `false` | Send all logs to SysLog (Unix) or EventLog (Windows) | 419 | `--listen-address` | empty | Address (`<host>:<port>`) on which the Prometheus metrics HTTP server should be listening | 420 421 ### `gitlab-runner run-single` 422 423 This is a supplementary command that can be used to run only a single build 424 from a single GitLab instance. It doesn't use any configuration file and 425 requires to pass all options either as parameters or environment variables. 426 The GitLab URL and Runner token need to be specified too. 427 428 For example: 429 430 ```bash 431 gitlab-runner run-single -u http://gitlab.example.com -t my-runner-token --executor docker --docker-image ruby:2.1 432 ``` 433 434 You can see all possible configuration options by using the `--help` flag: 435 436 ```bash 437 gitlab-runner run-single --help 438 ``` 439 440 You can use the `--max-builds` option to control how many builds the runner will execute before exiting. The 441 default of `0` means that the runner has no build limit and will run jobs forever. 442 443 You can also use the `--wait-timeout` option to control how long the runner will wait for a job before 444 exiting. The default of `0` means that the runner has no timeout and will wait forever between jobs. 445 446 ### `gitlab-runner exec` 447 448 > Notice: Not all features of `.gitlab-ci.yml` are supported by `exec`. Please 449 check what exactly is supported in the [limitations of `gitlab-runner exec`](#limitations-of-gitlab-runner-exec) 450 section. 451 452 This command allows you to run builds locally, trying to replicate the CI 453 environment as much as possible. It doesn't need to connect to GitLab, instead 454 it reads the local `.gitlab-ci.yml` and creates a new build environment in 455 which all the build steps are executed. 456 457 This command is useful for fast checking and verifying `.gitlab-ci.yml` as well 458 as debugging broken builds since everything is run locally. 459 460 When executing `exec` you need to specify the executor and the job name that is 461 present in `.gitlab-ci.yml`. The command should be executed from the root 462 directory of your Git repository that contains `.gitlab-ci.yml`. 463 464 `gitlab-runner exec` will clone the current state of the local Git repository. 465 Make sure you have committed any changes you want to test beforehand. 466 467 For example, the following command will execute the job named **tests** locally 468 using a shell executor: 469 470 ```bash 471 gitlab-runner exec shell tests 472 ``` 473 474 To see a list of available executors, run: 475 476 ```bash 477 gitlab-runner exec 478 ``` 479 480 To see a list of all available options for the `shell` executor, run: 481 482 ```bash 483 gitlab-runner exec shell 484 ``` 485 486 If you want to use the `docker` executor with the `exec` command, use that in 487 context of `docker-machine shell` or `boot2docker shell`. This is required to 488 properly map your local directory to the directory inside the Docker container. 489 490 #### Limitations of `gitlab-runner exec` 491 492 With current implementation of `exec` some of the features of GitLab CI will 493 not work or may work partially. 494 495 We're currently thinking about how to replace current `exec` implementation, 496 to make fully compatible with all features. Please track [the issue][exec-replacement-issue] 497 for more details. 498 499 **Compatibility table - features based on `.gitlab-ci.yml`** 500 501 | GitLab CI feature | Available with `exec` | Comments | 502 |-------------------|-----------------------|----------| 503 | image | yes | extended configuration (`name`, `entrypoint`) are also supported | 504 | services | yes | extended configuration (`name`, `alias`, `entrypoint`, `command`) are also supported | 505 | stages | no | `exec` can only run one job, independently from others | 506 | before_script | yes | supports both global and job-level `before_script` | 507 | after_script | partially | global `after_script` is not supported, only job-level `after_script`; only commands are taken in consideration, `when` is hardcoded to `always` | 508 | variables | yes | Supports default (partially), global and job-level variables; default variables are pre-set as can be seen in <https://gitlab.com/gitlab-org/gitlab-runner/blob/master/helpers/gitlab_ci_yaml_parser/parser.go#L147> | 509 | artifacts | no | | 510 | cache | partially | Regarding the specific configuration it may or may not work as expected | 511 | cache:policy | no | | 512 | environment | no | | 513 | only | no | | 514 | except | no | | 515 | `allow_failure` | no | `exec` just exits with the result of job; it's callers responsibility to decide if failure is OK or not | 516 | tags | no | | 517 | when | no | | 518 | dependencies | no | | 519 | coverage | no | | 520 | retry | no | | 521 | hidden keys | no | If explicitly asked to run, `exec` will try to run such job | 522 | YAML features | yes | Anchors (`&`), aliases (`*`), map merging (`<<`) are part of YAML specification and are handled by the parser | 523 | pages | partially | Job's script will be executed if explicitly asked, but it doesn't affect pages state, which is managed by GitLab | 524 525 **Compatibility table - features based on variables** 526 527 | GitLab CI feature | Available with `exec` | Comments | 528 |----------------------------|-----------------------|----------| 529 | GIT_STRATEGY | yes | | 530 | GIT_CHECKOUT | yes | | 531 | GIT_SUBMODULE_STRATEGY | yes | | 532 | GET_SOURCES_ATTEMPTS | yes | | 533 | ARTIFACT_DOWNLOAD_ATTEMPTS | no | artifacts are not supported | 534 | RESTORE_CACHE_ATTEMPTS | yes | | 535 | GIT_DEPTH | yes | | 536 537 **Compatibility table - other features** 538 539 | GitLab CI feature | Available with `exec` | Comments | 540 |-------------------|-----------------------|----------| 541 | Secret Variables | no | | 542 | triggers | no | | 543 | schedules | no | | 544 | job timeout | no | hardcoded to 1 hour | 545 | `[ci skip]` | no | | 546 547 **Other requirements and limitations** 548 549 `gitlab-runner exec docker` can only be used when Docker is installed locally. 550 This is needed because GitLab Runner is using host-bind volumes to access the 551 Git sources. 552 553 ## Internal commands 554 555 GitLab Runner is distributed as a single binary and contains a few internal 556 commands that are used during builds. 557 558 ### `gitlab-runner artifacts-downloader` 559 560 Download the artifacts archive from GitLab. 561 562 ### `gitlab-runner artifacts-uploader` 563 564 Upload the artifacts archive to GitLab. 565 566 ### `gitlab-runner cache-archiver` 567 568 Create a cache archive, store it locally or upload it to an external server. 569 570 ### `gitlab-runner cache-extractor` 571 572 Restore the cache archive from a locally or externally stored file. 573 574 ## Troubleshooting 575 576 Below are some common pitfalls. 577 578 ### **Access Denied** when running the service-related commands 579 580 Usually the [service related commands](#service-related-commands) require 581 administrator privileges: 582 583 - On Unix (Linux, macOS, FreeBSD) systems, prefix `gitlab-runner` with `sudo` 584 - On Windows systems use the elevated command prompt. 585 Run an `Administrator` command prompt. 586 The simplest way is to write `Command Prompt` in the Windows search field, 587 right click and select `Run as administrator`. You will be asked to confirm 588 that you want to execute the elevated command prompt. 589 590 [exec-replacement-issue]: https://gitlab.com/gitlab-org/gitlab-runner/issues/2797