github.com/secure-build/gitlab-runner@v12.5.0+incompatible/docs/configuration/advanced-configuration.md (about)

     1  ---
     2  table_display_block: true
     3  ---
     4  
     5  # Advanced configuration
     6  
     7  GitLab Runner configuration uses the [TOML][] format.
     8  
     9  The file to be edited can be found in:
    10  
    11  1. `/etc/gitlab-runner/config.toml` on \*nix systems when GitLab Runner is
    12     executed as root (**this is also path for service configuration**)
    13  1. `~/.gitlab-runner/config.toml` on \*nix systems when GitLab Runner is
    14     executed as non-root
    15  1. `./config.toml` on other systems
    16  
    17  ## The global section
    18  
    19  This defines global settings of GitLab Runner.
    20  
    21  | Setting | Description |
    22  | ------- | ----------- |
    23  | `concurrent`     | limits how many jobs globally can be run concurrently. The most upper limit of jobs using all defined runners. `0` **does not** mean unlimited |
    24  | `log_level`      | Log level (options: debug, info, warn, error, fatal, panic). Note that this setting has lower priority than level set by command line argument `--debug`, `-l` or `--log-level` |
    25  | `log_format`     | Log format (options: runner, text, json). Note that this setting has lower priority than format set by command line argument `--log-format` |
    26  | `check_interval` | defines the interval length, in seconds, between new jobs check. The default value is `3`; if set to `0` or lower, the default value will be used. |
    27  | `sentry_dsn`     | enable tracking of all system level errors to sentry |
    28  | `listen_address` | address (`<host>:<port>`) on which the Prometheus metrics HTTP server should be listening |
    29  
    30  Example:
    31  
    32  ```bash
    33  concurrent = 4
    34  log_level = "warning"
    35  ```
    36  
    37  ### How `check_interval` works
    38  
    39  If there is more than one `[[runners]]` section in `config.toml` (let's call them workers),
    40  the interval between requests to GitLab are more frequent than one could expect. GitLab Runner
    41  contains a loop that constantly schedules a request that should be made for a worker against
    42  the GitLab instance it's configured for.
    43  
    44  GitLab Runner tries to ensure that subsequent requests for one worker will be done in the specified interval,
    45  so the value of `check_interval` is divided by the number of the `[[runners]]` sections. The loop will next
    46  iterate over all sections, schedule a request for each of them, and will sleep for the calculated amount
    47  of time. Things get interesting when the workers are tied to a different GitLab instance.
    48  Consider the following example.
    49  
    50  If one would set `check_interval = 10`, and there were 2 workers in total (`runner-1` and `runner-2`),
    51  a subsequent request would be made each 10 seconds. The loop would look like:
    52  
    53  1. Get `check_interval` value (`10s`).
    54  1. Get list of workers (`runner-1`, `runner-2`).
    55  1. Calculate the sleep interval (`10s / 2 = 5s`).
    56  1. Start an infinite loop:
    57      1. Request a job for `runner-1`.
    58      1. Sleep for `5s`.
    59      1. Request a job for `runner-2`.
    60      1. Sleep for `5s`.
    61      1. Repeat.
    62  
    63  So, a request from the Runner's process is made each 5s. If `runner-1` and `runner-2` are connected to the same
    64  GitLab instance, it means that the request to this GitLab instance will receive a new request from this Runner
    65  also each 5s. But as you can see, between the first request for `runner-1` and second request for `runner-1`
    66  there are two sleeps taking 5s, so finally it's ~10s between subsequent requests for `runner-1`. The same goes
    67  for `runner-2`. If you define more workers, the sleep interval will be smaller, but a request for a worker will
    68  be repeated after all requests for the other workers + their sleeps are called.
    69  
    70  ## The `[session_server]` section
    71  
    72  NOTE: **Note:**
    73  `session_server` is not yet supported by
    74  [`gitlab-runner` helm chart](https://docs.gitlab.com/charts/charts/gitlab/gitlab-runner/index.html),
    75  but support [is planned](https://gitlab.com/gitlab-org/charts/gitlab-runner/issues/79).
    76  
    77  The section `[session_server]` is a system runner level configuration, so it should be specified at the root level,
    78  not per executor i.e. it should be outside `[[runners]]` section. The session server allows the user to interact
    79  with jobs that the Runner is responsible for. A good example of this is the
    80  [interactive web terminal](https://docs.gitlab.com/ee/ci/interactive_web_terminal/index.html).
    81  
    82  Both `listen_address` and `advertise_address` should be provided in the form
    83  of `host:port`, where `host` may be an IP address (e.g., `127.0.0.1:8093`)
    84  or a domain (e.g., `my-runner.example.com:8093`). The Runner will create a
    85  TLS certificate automatically to have a secure connection.
    86  
    87  If you want to disable the session server, just delete the `[session_server]`
    88  section and terminal support will be disabled.
    89  
    90  | Setting | Description |
    91  | ------- | ----------- |
    92  | `listen_address` | An internal URL to be used for the session server. |
    93  | `advertise_address`| The URL that the Runner will expose to GitLab to be used to access the session server. Fallbacks to `listen_address` if not defined.   |
    94  | `session_timeout` | How long in seconds the session can stay active after the job completes (which will block the job from finishing), defaults to `1800` (30 minutes). |
    95  
    96  Example:
    97  
    98  ```bash
    99  [session_server]
   100    listen_address = "0.0.0.0:8093" #  listen on all available interfaces on port 8093
   101    advertise_address = "runner-host-name.tld:8093"
   102    session_timeout = 1800
   103  ```
   104  
   105  ## The `[[runners]]` section
   106  
   107  This defines one runner entry.
   108  
   109  | Setting | Description |
   110  | ------- | ----------- |
   111  | `name`               | The Runner's description, just informatory |
   112  | `url`                | GitLab URL |
   113  | `token`              | The Runner's special token (not to be confused with the registration token) |
   114  | `tls-ca-file`        | File containing the certificates to verify the peer when using HTTPS |
   115  | `tls-cert-file`      | File containing the certificate to authenticate with the peer when using HTTPS |
   116  | `tls-key-file`       | File containing the private key to authenticate with the peer when using HTTPS |
   117  | `limit`              | Limit how many jobs can be handled concurrently by this token. `0` (default) simply means don't limit |
   118  | `executor`           | Select how a project should be built, see next section |
   119  | `shell`              | Name of shell to generate the script. Default value is [platform dependent](../shells/index.md#overview). |
   120  | `builds_dir`         | Absolute path to a directory where builds will be stored in context of selected executor (Locally, Docker, SSH) |
   121  | `cache_dir`          | Absolute path to a directory where build caches will be stored in context of selected executor (locally, Docker, SSH). If the `docker` executor is used, this directory needs to be included in its `volumes` parameter. |
   122  | `environment`        | Append or overwrite environment variables |
   123  | `request_concurrency` | Limit number of concurrent requests for new jobs from GitLab (default 1) |
   124  | `output_limit`       | Set maximum build log size in kilobytes, by default set to 4096 (4MB) |
   125  | `pre_clone_script`   | Commands to be executed on the Runner before cloning the Git repository. this can be used to adjust the Git client configuration first, for example. To insert multiple commands, use a (triple-quoted) multi-line string or "\n" character. |
   126  | `pre_build_script`   | Commands to be executed on the Runner after cloning the Git repository, but before executing the build. To insert multiple commands, use a (triple-quoted) multi-line string or "\n" character. |
   127  | `post_build_script`  | Commands to be executed on the Runner just after executing the build, but before executing `after_script`. To insert multiple commands, use a (triple-quoted) multi-line string or "\n" character. |
   128  | `clone_url`          | Overwrite the URL for the GitLab instance. Used if the Runner can't connect to GitLab on the URL GitLab exposes itself. |
   129  | `debug_trace_disabled` | Disables the `CI_DEBUG_TRACE` feature. When set to true, then debug log (trace) will remain disabled even if `CI_DEBUG_TRACE` will be set to `true` by the user. |
   130  
   131  Example:
   132  
   133  ```bash
   134  [[runners]]
   135    name = "ruby-2.1-docker"
   136    url = "https://CI/"
   137    token = "TOKEN"
   138    limit = 0
   139    executor = "docker"
   140    builds_dir = ""
   141    shell = ""
   142    environment = ["ENV=value", "LC_ALL=en_US.UTF-8"]
   143    clone_url = "http://gitlab.example.local"
   144  ```
   145  
   146  ### How `clone_url` works
   147  
   148  In cases where the GitLab instance is exposed to an URL which can't be used
   149  by the runner, a `clone_url` can be configured. For example; GitLab is exposed
   150  to `https://gitlab.example.com`, but the runner can't reach that because of
   151  a firewall setup. If the runner can reach the node on `192.168.1.23`,
   152  the `clone_url` should be set to `"http://192.168.1.23`.
   153  
   154  Only if the `clone_url` is set, the runner will construct a clone URL in the form
   155  of `http://gitlab-ci-token:s3cr3tt0k3n@192.168.1.23/namespace/project.git`.
   156  
   157  ## The EXECUTORS
   158  
   159  There are a couple of available executors currently.
   160  
   161  | Executor | Description |
   162  | -------- | ----------- |
   163  | `shell`       | run build locally, default |
   164  | `docker`      | run build using Docker container. This requires the presence of `[runners.docker]` and [Docker Engine][] installed on a system that the Runner will run the job on. |
   165  | `docker-windows` | run build using Windows Docker container. This requires the presence of `[runners.docker]` and [Docker Engine][] installed on a Windows system. |
   166  | `docker-ssh`  | run build using Docker container, but connect to it with SSH - this requires the presence of `[runners.docker]` , `[runners.ssh]` and [Docker Engine][] installed on the system that the Runner runs. **Note: This will run the docker container on the local machine, it just changes how the commands are run inside that container. If you want to run docker commands on an external machine, then you should change the `host` parameter in the `runners.docker` section.**|
   167  | `ssh`         | run build remotely with SSH - this requires the presence of `[runners.ssh]` |
   168  | `parallels`   | run build using Parallels VM, but connect to it with SSH - this requires the presence of `[runners.parallels]` and `[runners.ssh]` |
   169  | `virtualbox`  | run build using VirtualBox VM, but connect to it with SSH - this requires the presence of `[runners.virtualbox]` and `[runners.ssh]` |
   170  | `docker+machine` | like `docker`, but uses [auto-scaled Docker machines](autoscale.md) - this requires the presence of `[runners.docker]` and `[runners.machine]` |
   171  | `docker-ssh+machine` | like `docker-ssh`, but uses [auto-scaled Docker machines](autoscale.md) - this requires the presence of `[runners.docker]` and `[runners.machine]` |
   172  | `kubernetes` | run build using Kubernetes Pods - this requires the presence of `[runners.kubernetes]` |
   173  
   174  ## The SHELLS
   175  
   176  There are a couple of available shells that can be run on different platforms.
   177  
   178  | Shell | Description |
   179  | ----- | ----------- |
   180  | `bash`        | generate Bash (Bourne-shell) script. All commands executed in Bash context (default for all Unix systems) |
   181  | `sh`          | generate Sh (Bourne-shell) script. All commands executed in Sh context (fallback for `bash` for all Unix systems) |
   182  | `cmd`         | generate Windows Batch script. All commands are executed in Batch context (default for Windows) |
   183  | `powershell`  | generate Windows PowerShell script. All commands are executed in PowerShell context |
   184  
   185  ## The `[runners.docker]` section
   186  
   187  This defines the Docker Container parameters.
   188  
   189  | Parameter | Description |
   190  | --------- | ----------- |
   191  | `host`                         | Specify custom Docker endpoint, by default `DOCKER_HOST` environment is used or `unix:///var/run/docker.sock` |
   192  | `hostname`                     | Specify custom hostname for Docker container |
   193  | `runtime`                      | Specify a runtime for Docker container |
   194  | `tls_cert_path`                | When set it will use `ca.pem`, `cert.pem` and `key.pem` from that folder to make secure TLS connection to Docker (useful in boot2docker) |
   195  | `tls_verify`                   | Enable or disable TLS verification of connections to Docker daemon. Disabled by default. |
   196  | `image`                        | Use this image to run builds |
   197  | `memory`                       | String value containing the memory limit |
   198  | `memory_swap`                  | String value containing the total memory limit |
   199  | `memory_reservation`           | String value containing the memory soft limit |
   200  | `oom_kill_disable`             | Do not kill processes in a container if an out-of-memory (OOM) error occurs |
   201  | `cpuset_cpus`                  | String value containing the cgroups CpusetCpus to use |
   202  | `cpus`                         | String value of number of CPUs (available in docker 1.13 or later) |
   203  | `dns`                          | A list of DNS servers for the container to use |
   204  | `dns_search`                   | A list of DNS search domains |
   205  | `privileged`                   | Make container run in Privileged mode (insecure) |
   206  | `disable_entrypoint_overwrite` | Disable the image entrypoint overwriting |
   207  | `userns_mode`                  | Sets the usernamespace mode for the container when usernamespace remapping option is enabled. (available in docker 1.10 or later) |
   208  | `cap_add`                      | Add additional Linux capabilities to the container |
   209  | `cap_drop`                     | Drop additional Linux capabilities from the container |
   210  | `security_opt`                 | Set security options (--security-opt in docker run), takes a list of ':' separated key/values |
   211  | `devices`                      | Share additional host devices with the container |
   212  | `cache_dir`                    | Specify where Docker caches should be stored (this can be absolute or relative to current working directory). See `disable_cache` for more information. |
   213  | `disable_cache`                | The Docker executor has 2 levels of caching: a global one (like any other executor) and a local cache based on Docker volumes. This configuration flag acts only on the local one which disables the use of automatically created (not mapped to a host directory) cache volumes. In other words, it only prevents creating a container that holds temporary files of builds, it does not disable the cache if the Runner is configured in [distributed cache mode](autoscale.md#distributed-runners-caching). |
   214  | `network_mode`              | Add container to a custom network |
   215  | `wait_for_services_timeout` | Specify how long to wait for docker services, set to 0 to disable, default: 30 |
   216  | `volumes`                   | Specify additional volumes that should be mounted (same syntax as Docker's `-v` flag) |
   217  | `extra_hosts`               | Specify hosts that should be defined in container environment |
   218  | `shm_size`                  | Specify shared memory size for images (in bytes) |
   219  | `volumes_from`              | Specify a list of volumes to inherit from another container in the form `\<container name\>[:\<ro&#124;rw\>]` |
   220  | `volume_driver`             | Specify the volume driver to use for the container |
   221  | `links`                     | Specify containers which should be linked with building container |
   222  | `services`                  | Specify additional services that should be run with build. Please visit [Docker Registry](https://hub.docker.com) for list of available applications. Each service will be run in separate container and linked to the build. |
   223  | `allowed_images`            | Specify wildcard list of images that can be specified in `.gitlab-ci.yml`. If not present all images are allowed (equivalent to `["*/*:*"]`) |
   224  | `allowed_services`          | Specify wildcard list of services that can be specified in `.gitlab-ci.yml`. If not present all images are allowed (equivalent to `["*/*:*"]`) |
   225  | `pull_policy`               | Specify the image pull policy: `never`, `if-not-present` or `always` (default); read more in the [pull policies documentation](../executors/docker.md#how-pull-policies-work) |
   226  | `sysctls`                   | specify the sysctl options |
   227  | `helper_image`              | (Advanced) [Override the default helper image](#helper-image) used to clone repos and upload artifacts. |
   228  
   229  Example:
   230  
   231  ```bash
   232  [runners.docker]
   233    host = ""
   234    hostname = ""
   235    tls_cert_path = "/Users/ayufan/.boot2docker/certs"
   236    image = "ruby:2.1"
   237    memory = "128m"
   238    memory_swap = "256m"
   239    memory_reservation = "64m"
   240    oom_kill_disable = false
   241    cpuset_cpus = "0,1"
   242    cpus = "2"
   243    dns = ["8.8.8.8"]
   244    dns_search = [""]
   245    privileged = false
   246    userns_mode = "host"
   247    cap_add = ["NET_ADMIN"]
   248    cap_drop = ["DAC_OVERRIDE"]
   249    devices = ["/dev/net/tun"]
   250    disable_cache = false
   251    wait_for_services_timeout = 30
   252    cache_dir = ""
   253    volumes = ["/data", "/home/project/cache"]
   254    extra_hosts = ["other-host:127.0.0.1"]
   255    shm_size = 300000
   256    volumes_from = ["storage_container:ro"]
   257    links = ["mysql_container:mysql"]
   258    services = ["mysql", "redis:2.8", "postgres:9"]
   259    allowed_images = ["ruby:*", "python:*", "php:*"]
   260    allowed_services = ["postgres:9.4", "postgres:latest"]
   261    [runners.docker.sysctls]
   262      "net.ipv4.ip_forward" = "1"
   263  ```
   264  
   265  ### Volumes in the `[runners.docker]` section
   266  
   267  You can find the complete guide of Docker volume usage
   268  [here](https://docs.docker.com/userguide/dockervolumes/).
   269  
   270  Let's use some examples to explain how it work (assuming you have a working
   271  runner).
   272  
   273  #### Example 1: adding a data volume
   274  
   275  A data volume is a specially-designated directory within one or more containers
   276  that bypasses the Union File System. Data volumes are designed to persist data,
   277  independent of the container's life cycle.
   278  
   279  ```bash
   280  [runners.docker]
   281    host = ""
   282    hostname = ""
   283    tls_cert_path = "/Users/ayufan/.boot2docker/certs"
   284    image = "ruby:2.1"
   285    privileged = false
   286    disable_cache = true
   287    volumes = ["/path/to/volume/in/container"]
   288  ```
   289  
   290  This will create a new volume inside the container at `/path/to/volume/in/container`.
   291  
   292  #### Example 2: mount a host directory as a data volume
   293  
   294  In addition to creating a volume using a data volume, you can also mount
   295  a directory from your Docker daemon's host into a container. It's useful
   296  when you want to store directories outside the container.
   297  
   298  ```bash
   299  [runners.docker]
   300    host = ""
   301    hostname = ""
   302    tls_cert_path = "/Users/ayufan/.boot2docker/certs"
   303    image = "ruby:2.1"
   304    privileged = false
   305    disable_cache = true
   306    volumes = ["/path/to/bind/from/host:/path/to/bind/in/container:rw"]
   307  ```
   308  
   309  This will use `/path/to/bind/from/host` of the CI host inside the container at
   310  `/path/to/bind/in/container`.
   311  
   312  NOTE: **Note:**
   313  GitLab Runner 11.11 and newer [will mount the host
   314  directory](https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/1261)
   315  for the defined [services](https://docs.gitlab.com/ee/ci/services/) as
   316  well.
   317  
   318  ### Using a private container registry
   319  
   320  > **Notes:**
   321  >
   322  >- This feature requires GitLab Runner **1.8** or higher
   323  >- For GitLab Runner versions **>= 0.6, <1.8** there was a partial
   324  >  support for using private registries, which required manual configuration
   325  >  of credentials on runner's host. We recommend to upgrade your Runner to
   326  >  at least version **1.8** if you want to use private registries.
   327  >- Using private registries with the `if-not-present` pull policy may introduce
   328  >  [security implications][secpull]. To fully understand how pull policies work,
   329  >  read the [pull policies documentation](../executors/docker.md#how-pull-policies-work).
   330  
   331  If you want to use private registries as a source of images for your builds,
   332  you can set the authorization configuration in the `DOCKER_AUTH_CONFIG`
   333  [variable]. It can be set in both GitLab Variables section of
   334  a project and in the `config.toml` file.
   335  
   336  For a detailed example, visit the [Using Docker images documentation][priv-example].
   337  
   338  The steps performed by the Runner can be summed up to:
   339  
   340  1. The registry name is found from the image name.
   341  1. If the value is not empty, the executor will search for the authentication
   342     configuration for this registry.
   343  1. Finally, if an authentication corresponding to the specified registry is
   344     found, subsequent pulls will make use of it.
   345  
   346  Now that the Runner is set up to authenticate against your private registry,
   347  learn [how to configure `.gitlab-ci.yml`][yaml-priv-reg] in order to use that
   348  registry.
   349  
   350  #### Support for GitLab integrated registry
   351  
   352  > **Note:**
   353  To work automatically with private/protected images from
   354  GitLab integrated registry it needs at least GitLab CE/EE **8.14**
   355  and GitLab Runner **1.8**.
   356  
   357  Starting with GitLab CE/EE 8.14, GitLab will send credentials for its integrated
   358  registry along with the build data. These credentials will be automatically
   359  added to registries authorization parameters list.
   360  
   361  After this authorization against the registry will be proceed like for
   362  configuration added with `DOCKER_AUTH_CONFIG` variable.
   363  
   364  Thanks to this, in your builds you can use any image from you GitLab integrated
   365  registry, even if the image is private/protected. To fully understand for
   366  which images the builds will have access, read the
   367  [New CI build permissions model][ci-build-permissions-model] documentation.
   368  
   369  #### Precedence of Docker authorization resolving
   370  
   371  As described above, GitLab Runner can authorize Docker against a registry by
   372  using credentials sent in different way. To find a proper registry, the following
   373  precedence is taken into account:
   374  
   375  1. Credentials configured with `DOCKER_AUTH_CONFIG`.
   376  1. Credentials configured locally on Runner's host with `~/.docker/config.json`
   377     or `~/.dockercfg` files (e.g., by running `docker login` on the host).
   378  1. Credentials sent by default with job's payload (e.g., credentials for _integrated
   379     registry_ described above).
   380  
   381  The first found credentials for the registry will be used. So for example,
   382  if you add some credentials for the _integrated registry_ with the
   383  `DOCKER_AUTH_CONFIG` variable, then the default credentials will be overridden.
   384  
   385  #### Restrict `allowed_images` to private registry
   386  
   387  For certain setups you will restrict access of the build jobs to docker images
   388  which comes from your private docker registry. In that case set
   389  
   390  ```bash
   391  [runners.docker]
   392    ...
   393    allowed_images = ["my.registry.tld:5000/*:*"]
   394  ```
   395  
   396  ## The `[runners.parallels]` section
   397  
   398  This defines the Parallels parameters.
   399  
   400  | Parameter | Description |
   401  | --------- | ----------- |
   402  | `base_name`         | name of Parallels VM which will be cloned |
   403  | `template_name`     | custom name of Parallels VM linked template (optional) |
   404  | `disable_snapshots` | if disabled the VMs will be destroyed after build |
   405  
   406  Example:
   407  
   408  ```bash
   409  [runners.parallels]
   410    base_name = "my-parallels-image"
   411    template_name = ""
   412    disable_snapshots = false
   413  ```
   414  
   415  ## The `[runners.virtualbox]` section
   416  
   417  This defines the VirtualBox parameters. This executor relies on
   418  `vboxmanage` as executable to control VirtualBox machines so you have to adjust
   419  your `PATH` environment variable on Windows hosts:
   420  `PATH=%PATH%;C:\Program Files\Oracle\VirtualBox`.
   421  
   422  | Parameter | Explanation |
   423  | --------- | ----------- |
   424  | `base_name`         | name of VirtualBox VM which will be cloned |
   425  | `base_snapshot`     | name or UUID of a specific snapshot of the VM from which to create a linked clone. If this is empty or omitted, the current snapshot will be used. If there is no current snapshot, one will be created unless `disable_snapshots` is true, in which case a full clone of the base VM will be made. |
   426  | `disable_snapshots` | if disabled the VMs will be destroyed after build |
   427  
   428  Example:
   429  
   430  ```bash
   431  [runners.virtualbox]
   432    base_name = "my-virtualbox-image"
   433    base_snapshot = "my-image-snapshot"
   434    disable_snapshots = false
   435  ```
   436  
   437  ## The `[runners.ssh]` section
   438  
   439  This defines the SSH connection parameters.
   440  
   441  | Parameter  | Description |
   442  | ---------- | ----------- |
   443  | `host`     | where to connect (overridden when using `docker-ssh`) |
   444  | `port`     | specify port, default: 22 |
   445  | `user`     | specify user |
   446  | `password` | specify password |
   447  | `identity_file` | specify file path to SSH private key (id_rsa, id_dsa or id_edcsa). The file needs to be stored unencrypted |
   448  
   449  Example:
   450  
   451  ```
   452  [runners.ssh]
   453    host = "my-production-server"
   454    port = "22"
   455    user = "root"
   456    password = "production-server-password"
   457    identity_file = ""
   458  ```
   459  
   460  ## The `[runners.machine]` section
   461  
   462  > Added in GitLab Runner v1.1.0.
   463  
   464  This defines the Docker Machine based autoscaling feature. More details can be
   465  found in the separate [runners autoscale documentation](autoscale.md).
   466  
   467  | Parameter           | Description |
   468  |---------------------|-------------|
   469  | `IdleCount`         | Number of machines, that need to be created and waiting in _Idle_ state. |
   470  | `IdleTime`          | Time (in seconds) for machine to be in _Idle_ state before it is removed. |
   471  | `OffPeakPeriods`    | Time periods when the scheduler is in the OffPeak mode. An array of cron-style patterns (described below). |
   472  | `OffPeakTimezone`   | Timezone for the times given in OffPeakPeriods. A timezone string like `Europe/Berlin`. Defaults to the locale system setting of the host if omitted or empty. GitLab Runner attempts to locate the timezone database in the directory or uncompressed zip file named by the `ZONEINFO` environment variable, then looks in known installation locations on Unix systems, and finally looks in `$GOROOT/lib/time/zoneinfo.zip`. |
   473  | `OffPeakIdleCount`  | Like `IdleCount`, but for _Off Peak_ time periods. |
   474  | `OffPeakIdleTime`   | Like `IdleTime`, but for _Off Peak_ time mperiods. |
   475  | `MaxBuilds`         | Builds count after which machine will be removed. |
   476  | `MachineName`       | Name of the machine. It **must** contain `%s`, which will be replaced with a unique machine identifier. |
   477  | `MachineDriver`     | Docker Machine `driver` to use. More details can be found in the [Docker Machine configuration section](autoscale.md#supported-cloud-providers). |
   478  | `MachineOptions`    | Docker Machine options. More details can be found in the [Docker Machine configuration section](autoscale.md#supported-cloud-providers). |
   479  
   480  Example:
   481  
   482  ```bash
   483  [runners.machine]
   484    IdleCount = 5
   485    IdleTime = 600
   486    OffPeakPeriods = [
   487      "* * 0-10,18-23 * * mon-fri *",
   488      "* * * * * sat,sun *"
   489    ]
   490    OffPeakTimezone = "Europe/Berlin"
   491    OffPeakIdleCount = 1
   492    OffPeakIdleTime = 3600
   493    MaxBuilds = 100
   494    MachineName = "auto-scale-%s"
   495    MachineDriver = "digitalocean"
   496    MachineOptions = [
   497        "digitalocean-image=coreos-stable",
   498        "digitalocean-ssh-user=core",
   499        "digitalocean-access-token=DO_ACCESS_TOKEN",
   500        "digitalocean-region=nyc2",
   501        "digitalocean-size=4gb",
   502        "digitalocean-private-networking",
   503        "engine-registry-mirror=http://10.11.12.13:12345"
   504    ]
   505  ```
   506  
   507  ### OffPeakPeriods syntax
   508  
   509  The `OffPeakPeriods` setting contains an array of string patterns of
   510  time periods represented in a cron-style format. The line contains
   511  following fields:
   512  
   513  ```
   514  [second] [minute] [hour] [day of month] [month] [day of week] [year]
   515  ```
   516  
   517  Like in the standard cron configuration file, the fields can contain single
   518  values, ranges, lists and asterisks. A detailed description of the syntax
   519  can be found [here][cronvendor].
   520  
   521  ## The `[runners.custom]` section
   522  
   523  Define configuration for the [custom
   524  executor](../executors/custom.md).
   525  
   526  | Parameter               | Type         | Required | Description                                                                                                                                                                                                                                                                                         |
   527  |-------------------------|--------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
   528  | `config_exec`           | string       | ✗        | Path to an executable to allow the user to override some configuration settings before the build starts. These values will override the ones set inside of the [`[[runners]]`](#the-runners-section) section. [The custom executor documentation](../executors/custom.md#config) has the full list. |
   529  | `config_args`           | string array | ✗        | First set of arguments passed to the `config_exec` executable.                                                                                                                                                                                                                                      |
   530  | `config_exec_timeout`   | integer      | ✗        | Timeout in seconds for `config_exec` to finish execution. Default to 1 hour.                                                                                                                                                                                                                        |
   531  | `prepare_exec`          | string       | ✗        | Path to an executable to prepare the environment.                                                                                                                                                                                                                                                   |
   532  | `prepare_args`          | string array | ✗        | First set of arguments passed to the `prepare_exec` executable.                                                                                                                                                                                                                                     |
   533  | `prepare_exec_timeout`  | integer      | ✗        | Timeout in seconds for `prepare_exec` to finish execution. Default to 1 hour.                                                                                                                                                                                                                       |
   534  | `run_exec`              | string       | ✓        | Path to an executable to run scripts in the environments. For example, the clone and build script.                                                                                                                                                                                                  |
   535  | `run_args`              | string array | ✗        | First set of arguments passed to the `run_exec` executable.                                                                                                                                                                                                                                         |
   536  | `cleanup_exec`          | string       | ✗        | Path to an executable to clean up the environment.                                                                                                                                                                                                                                                  |
   537  | `cleanup_args`          | string array | ✗        | First set of arguments passed to the `cleanup_exec` executable.                                                                                                                                                                                                                                     |
   538  | `cleanup_exec_timeout`  | integer      | ✗        | Timeout in seconds for `cleanup_exec` to finish execution. Default to 1 hour.                                                                                                                                                                                                                       |
   539  | `graceful_kill_timeout` | integer      | ✗        | Time to wait in seconds for `prepare_exec` and `cleanup_exec` if they are terminated (for example, during build cancellation). After this timeout, the process is killed. Defaults to 10 minutes.                                                                                                   |
   540  | `force_kill_timeout`    | integer      | ✗        | Time to wait in seconds after the kill signal is sent to the script. Defaults to 10 minutes.                                                                                                                                                                                                        |
   541  
   542  ## The `[runners.cache]` section
   543  
   544  > Introduced in GitLab Runner 1.1.0.
   545  
   546  This defines the distributed cache feature. More details can be found
   547  in the [runners autoscale documentation](autoscale.md#distributed-runners-caching).
   548  
   549  | Parameter        | Type             | Description |
   550  |------------------|------------------|-------------|
   551  | `Type`           | string           | One of: `s3`, `gcs`. |
   552  | `Path`           | string           | Name of the path to prepend to the cache URL. |
   553  | `Shared`         | boolean          | Enables cache sharing between runners, `false` by default. |
   554  
   555  CAUTION: **Important:**
   556  With GitLab Runner 11.3.0, the configuration parameters related to S3 were moved to a dedicated `[runners.cache.s3]` section.
   557  The old format of the configuration with S3 configured directly in `[runners.cache]` was deprecated with GitLab Runner 11.3.0.
   558  **With GitLab Runner 12.0.0 the old configuration syntax was removed and is no longer supported**.
   559  
   560  NOTE: **Note:**
   561  The cache mechanism uses pre-signed URLs to upload and download cache. URLs are being signed by GitLab Runner on its **own instance**.
   562  No matter if the job's script - so also the cache upload/download script - are being executed on local or external
   563  machines (e.g. `shell` or `docker` executors are running their scripts on the same
   564  machine where GitLab Runner process is running, while `virtualbox` or `docker+machine`
   565  connects to a separate VM to execute the script). This is done for security reasons:
   566  minimizing the possibility of leaking the cache adapter's credentials.
   567  
   568  NOTE: **Note:**
   569  Previous note implies [S3 cache adapter](#the-runnerscaches3-section), if configured to use
   570  IAM instance profile, will use the profile attached with GitLab Runner's machine.
   571  Similarly for [GCS cache adapter](#the-runnerscachegcs-section), if configured to
   572  use the `CredentialsFile`, the file needs to be present on GitLab Runner's machine.
   573  
   574  Below is a table containing a summary of `config.toml`, cli options and ENV variables for `register`:
   575  
   576  | Setting             | TOML field                               | CLI option for `register`      | ENV for `register`                | Before 12.0.0 TOML field            | Before 12.0.0 CLI option | Before 12.0.0 ENV         |
   577  |---------------------|------------------------------------------|--------------------------------|-----------------------------------|-------------------------------------|--------------------------|---------------------------|
   578  | Type                | `[runners.cache] -> Type`                | `--cache-type`                 | `$CACHE_TYPE`                     |                                     |                          |                           |
   579  | Path                | `[runners.cache] -> Path`                | `--cache-path`                 | `$CACHE_PATH`                     |                                     | `--cache-s3-cache-path`  | `$S3_CACHE_PATH`          |
   580  | Shared              | `[runners.cache] -> Shared`              | `--cache-shared`               | `$CACHE_SHARED`                   |                                     | `--cache-cache-shared`   |                           |
   581  | S3.ServerAddress    | `[runners.cache.s3] -> ServerAddress`    | `--cache-s3-server-address`    | `$CACHE_S3_SERVER_ADDRESS`        | `[runners.cache] -> ServerAddress`  |                          | `$S3_SERVER_ADDRESS`      |
   582  | S3.AccessKey        | `[runners.cache.s3] -> AccessKey`        | `--cache-s3-access-key`        | `$CACHE_S3_ACCESS_KEY`            | `[runners.cache] -> AccessKey`      |                          | `$S3_ACCESS_KEY`          |
   583  | S3.SecretKey        | `[runners.cache.s3] -> SecretKey`        | `--cache-s3-secret-key`        | `$CACHE_S3_SECRET_KEY`            | `[runners.cache] -> SecretKey`      |                          | `$S3_SECRET_KEY`          |
   584  | S3.BucketName       | `[runners.cache.s3] -> BucketName`       | `--cache-s3-bucket-name`       | `$CACHE_S3_BUCKET_NAME`           | `[runners.cache] -> BucketName`     |                          | `$S3_BUCKET_NAME`         |
   585  | S3.BucketLocation   | `[runners.cache.s3] -> BucketLocation`   | `--cache-s3-bucket-location`   | `$CACHE_S3_BUCKET_LOCATION`       | `[runners.cache] -> BucketLocation` |                          | `$S3_BUCKET_LOCATION`     |
   586  | S3.Insecure         | `[runners.cache.s3] -> Insecure`         | `--cache-s3-insecure`          | `$CACHE_S3_INSECURE`              | `[runners.cache] -> Insecure`       |                          | `$S3_INSECURE`            |
   587  | GCS.AccessID        | `[runners.cache.gcs] -> AccessID`        | `--cache-gcs-access-id`        | `$CACHE_GCS_ACCESS_ID`            |                                     |                          |                           |
   588  | GCS.PrivateKey      | `[runners.cache.gcs] -> PrivateKey`      | `--cache-gcs-private-key`      | `$CACHE_GCS_PRIVATE_KEY`          |                                     |                          |                           |
   589  | GCS.CredentialsFile | `[runners.cache.gcs] -> CredentialsFile` | `--cache-gcs-credentials-file` | `$GOOGLE_APPLICATION_CREDENTIALS` |                                     |                          |                           |
   590  | GCS.BucketName      | `[runners.cache.gcs] -> BucketName`      | `--cache-gcs-bucket-name`      | `$CACHE_GCS_BUCKET_NAME`          |                                     |                          |                           |
   591  
   592  ### The `[runners.cache.s3]` section
   593  
   594  NOTE: **Note:**
   595  Moved from the `[runners.cache]` section in GitLab Runner 11.3.0.
   596  
   597  Allows to configure S3 storage for cache. This section contains settings related to S3, that previously were
   598  present globally in the `[runners.cache]` section.
   599  
   600  | Parameter        | Type             | Description |
   601  |------------------|------------------|-------------|
   602  | `ServerAddress`  | string           | A `host:port` to the used S3-compatible server. |
   603  | `AccessKey`      | string           | The access key specified for your S3 instance. |
   604  | `SecretKey`      | string           | The secret key specified for your S3 instance. |
   605  | `BucketName`     | string           | Name of the storage bucket where cache will be stored. |
   606  | `BucketLocation` | string           | Name of S3 region. |
   607  | `Insecure`       | boolean          | Set to `true` if the S3 service is available by `HTTP`. Set to `false` by default. |
   608  
   609  Example:
   610  
   611  ```toml
   612  [runners.cache]
   613    Type = "s3"
   614    Path = "path/to/prefix"
   615    Shared = false
   616    [runners.cache.s3]
   617      ServerAddress = "s3.amazonaws.com"
   618      AccessKey = "AMAZON_S3_ACCESS_KEY"
   619      SecretKey = "AMAZON_S3_SECRET_KEY"
   620      BucketName = "runners-cache"
   621      BucketLocation = "eu-west-1"
   622      Insecure = false
   623  ```
   624  
   625  NOTE: **Note:**
   626  For Amazon's S3 service, the `ServerAddress` should always be `s3.amazonaws.com`. The Minio S3 client will
   627  get bucket metadata and modify the URL to point to the valid region (eg. `s3-eu-west-1.amazonaws.com`) itself.
   628  
   629  NOTE: **Note:**
   630  If any of `ServerAddress`, `AccessKey` or `SecretKey` aren't specified, then the S3 client will use the
   631  IAM instance profile available to the `gitlab-runner` instance. In an
   632  [autoscale](autoscale.md) configuration, this is *NOT* the machine created on
   633  demand that jobs are executed on.
   634  
   635  ### The `[runners.cache.gcs]` section
   636  
   637  > Introduced in GitLab Runner 11.3.0.
   638  
   639  Configure native support for Google Cloud Storage. Read the
   640  [Google Cloud Storage Authentication documentation](https://cloud.google.com/storage/docs/authentication#service_accounts)
   641  to check where these values come from.
   642  
   643  | Parameter         | Type             | Description |
   644  |-------------------|------------------|-------------|
   645  | `CredentialsFile` | string           | Path to the Google JSON key file. Currently only the `service_account` type is supported. If configured, takes precedence over `AccessID` and `PrivateKey` configured directly in `config.toml`. |
   646  | `AccessID`        | string           | ID of GCP Service Account used to access the storage. |
   647  | `PrivateKey`      | string           | Private key used to sign GCS requests. |
   648  | `BucketName`      | string           | Name of the storage bucket where cache will be stored. |
   649  
   650  Examples:
   651  
   652  **Credentials configured directly in `config.toml` file:**
   653  
   654  ```toml
   655  [runners.cache]
   656    Type = "gcs"
   657    Path = "path/to/prefix"
   658    Shared = false
   659    [runners.cache.gcs]
   660      AccessID = "cache-access-account@test-project-123456.iam.gserviceaccount.com"
   661      PrivateKey = "-----BEGIN PRIVATE KEY-----\nXXXXXX\n-----END PRIVATE KEY-----\n"
   662      BucketName = "runners-cache"
   663  ```
   664  
   665  **Credentials in JSON file downloaded from GCP:**
   666  
   667  ```toml
   668  [runners.cache]
   669    Type = "gcs"
   670    Path = "path/to/prefix"
   671    Shared = false
   672    [runners.cache.gcs]
   673      CredentialsFile = "/etc/gitlab-runner/service-account.json"
   674      BucketName = "runners-cache"
   675  ```
   676  
   677  ## The `[runners.kubernetes]` section
   678  
   679  > Added in GitLab Runner v1.6.0
   680  
   681  This defines the Kubernetes parameters.
   682  See [Kubernetes executor](../executors/kubernetes.md) for additional parameters.
   683  
   684  | Parameter        | Type    | Description |
   685  |------------------|---------|-------------|
   686  | `host`           | string  | Optional Kubernetes master host URL (auto-discovery attempted if not specified) |
   687  | `cert_file`      | string  | Optional Kubernetes master auth certificate |
   688  | `key_file`       | string  | Optional Kubernetes master auth private key |
   689  | `ca_file`        | string  | Optional Kubernetes master auth ca certificate |
   690  | `image`          | string  | Default docker image to use for builds when none is specified |
   691  | `namespace`      | string  | Namespace to run Kubernetes jobs in |
   692  | `privileged`     | boolean | Run all containers with the privileged flag enabled |
   693  | `node_selector`  | table   | A `table` of `key=value` pairs of `string=string`. Setting this limits the creation of pods to Kubernetes nodes matching all the `key=value` pairs |
   694  | `image_pull_secrets` | array | A list of secrets that are used to authenticate docker image pulling |
   695  
   696  Example:
   697  
   698  ```bash
   699  [runners.kubernetes]
   700    host = "https://45.67.34.123:4892"
   701    cert_file = "/etc/ssl/kubernetes/api.crt"
   702    key_file = "/etc/ssl/kubernetes/api.key"
   703    ca_file = "/etc/ssl/kubernetes/ca.crt"
   704    image = "golang:1.8"
   705    privileged = true
   706    image_pull_secrets = ["docker-registry-credentials"]
   707    [runners.kubernetes.node_selector]
   708      gitlab = "true"
   709  ```
   710  
   711  ## Helper image
   712  
   713  When one of `docker`, `docker+machine` or `kubernetes` executors is used, GitLab Runner uses a specific container
   714  to handle Git, artifacts and cache operations. This container is created from a special image, named `helper image`.
   715  
   716  The helper image is based on Alpine Linux and it's provided for amd64 and arm architectures. It contains
   717  a `gitlab-runner-helper` binary which is a special compilation of GitLab Runner binary, that contains only a subset
   718  of available commands, as well as Git, Git LFS, SSL certificates store and basic configuration of Alpine.
   719  
   720  When GitLab Runner is installed from the DEB/RPM packages, both images (`amd64` and `arm` based) are installed on the host.
   721  When the Runner prepares the environment for the job execution, if the image in specified version (based on Runner's Git
   722  revision) is not found on Docker Engine, it is automatically loaded. It works like that for both
   723  `docker` and `docker+machine` executors.
   724  
   725  Things work a little different for the `kubernetes` executor or when GitLab Runner is installed manually. For manual
   726  installations, the `gitlab-runner-helper` binary is not included and for the `kubernetes` executor,the API of Kubernetes
   727  doesn't allow to load the `gitlab-runner-helper` image from a local archive. In both cases, GitLab Runner will download
   728  the helper image from Docker Hub, from GitLab's official repository `gitlab/gitlab-runner-helper` by using the Runner's
   729  revision and architecture for defining which tag should be downloaded.
   730  
   731  ### Overriding the helper image
   732  
   733  In some cases, you may need to override the helper image. There are many reasons for doing this:
   734  
   735  1. **To speed up jobs execution**: In environments with slower internet connection, downloading over and over again the
   736     same image from Docker Hub may generate a significant increase of a job's timings. Downloading the helper image from
   737     a local registry (where the exact copy of `gitlab/gitlab-runner-helper:XYZ` is stored) may speed things up.
   738  
   739  1. **Security concerns**: Many people don't like to download external dependencies that were not checked before. There
   740     might be a business rule to use only dependencies that were reviewed and stored in local repositories.
   741  
   742  1. **Build environments without internet access**: In some cases, jobs are being executed in an environment which has
   743     a dedicated, closed network (this doesn't apply to the `kubernetes` executor where the image still needs to be downloaded
   744     from an external registry that is available at least to the Kubernetes cluster).
   745  
   746  1. **Additional software**: Some users may want to install some additional software to the helper image, like
   747     `openssh` to support submodules accessible via `git+ssh` instead of `git+http`.
   748  
   749  In any of the cases described above, it's possible to configure a custom image using the `helper_image` configuration field,
   750  that is available for the `docker`, `docker+machine` and `kubernetes` executors:
   751  
   752  ```toml
   753  [[runners]]
   754    (...)
   755    executor = "docker"
   756    [runners.docker]
   757      (...)
   758      helper_image = "my.registry.local/gitlab/gitlab-runner-helper:tag"
   759  ```
   760  
   761  Note that the version of the helper image should be considered as strictly coupled with the version of GitLab Runner.
   762  As it was described above, one of the main reasons of providing such images is that Runner is using the
   763  `gitlab-runner-helper` binary, and this binary is compiled from part of GitLab Runner sources which is using an internal
   764  API that is expected to be the same in both binaries.
   765  
   766  The Runner by default references to a `gitlab/gitlab-runner-helper:XYZ` image, where `XYZ` is based
   767  on the Runner's architecture and Git revision. Starting with **GitLab Runner 11.3** it's possible to define the version
   768  of used image automatically, by using one of the
   769  [version variables](https://gitlab.com/gitlab-org/gitlab-runner/blob/11-3-stable/common/version.go#L48-50):
   770  
   771  ```toml
   772  [[runners]]
   773    (...)
   774    executor = "docker"
   775    [runners.docker]
   776      (...)
   777      helper_image = "my.registry.local/gitlab/gitlab-runner-helper:x86_64-${CI_RUNNER_REVISION}"
   778  ```
   779  
   780  With that configuration, GitLab Runner will instruct the executor to use the image in version `x86_64-${CI_RUNNER_REVISION}`,
   781  which is based on its compilation data. After updating the Runner to a new version, this will ensure that the
   782  Runner will try to download the proper image. This of course means that the image should be uploaded to the registry
   783  before upgrading the Runner, otherwise the jobs will start failing with a "No such image" error.
   784  
   785  ## The `[runners.custom_build_dir]` section
   786  
   787  NOTE: **Note:**
   788  [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/1267) in GitLab Runner 11.10
   789  
   790  This section defines [custom build directories](https://docs.gitlab.com/ee/ci/yaml/README.html#custom-build-directories) parameters.
   791  
   792  Please notice, that the feature - if not configured explicitly - will be
   793  enabled by default for `kubernetes`, `docker`, `docker-ssh`, `docker+machine`
   794  and `docker-ssh+machine` executors. It will be disabled by default for all other
   795  executors.
   796  
   797  This feature requires that `GIT_CLONE_PATH` is within a path defined
   798  within `runners.builds_dir`. For the ease of using `builds_dir` the
   799  `$CI_BUILDS_DIR` variable can be used.
   800  
   801  The feature is by default enabled only for `docker` and `kubernetes` executors
   802  as they provide a good way to separate resources. This feature can be
   803  explicitly enabled for any executor, but special care should be taken when using
   804  with executors that share `builds_dir` and have `concurrent > 1`.
   805  
   806  | Parameter | Type    | Description |
   807  |-----------|---------|-------------|
   808  | `enabled` | boolean | Allow user to define a custom build directory for a job |
   809  
   810  Example:
   811  
   812  ```bash
   813  [runners.custom_build_dir]
   814    enabled = true
   815  ```
   816  
   817  ## Note
   818  
   819  If you'd like to deploy to multiple servers using GitLab CI, you can create a
   820  single script that deploys to multiple servers or you can create many scripts.
   821  It depends on what you'd like to do.
   822  
   823  [TOML]: https://github.com/toml-lang/toml
   824  [Docker Engine]: https://docs.docker.com/engine/
   825  [yaml-priv-reg]: https://docs.gitlab.com/ee/ci/yaml/README.html#image-and-services
   826  [ci-build-permissions-model]: https://docs.gitlab.com/ee/user/project/new_ci_build_permissions_model.html
   827  [secpull]: ../security/index.md#usage-of-private-docker-images-with-if-not-present-pull-policy
   828  
   829  [priv-example]: https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#define-an-image-from-a-private-container-registry
   830  [variable]: https://docs.gitlab.com/ee/ci/variables/#variables
   831  [cronvendor]: https://github.com/gorhill/cronexpr#implementation