gitlab.com/jfprevost/gitlab-runner-notlscheck@v11.11.4+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      gitlab-runner register --name my-runner --url http://gitlab.example.com --registration-token my-registration-token
   209  
   210  Or by configuring the environment variable before the `register` command:
   211  
   212      export CI_SERVER_URL=http://gitlab.example.com
   213      export RUNNER_NAME=my-runner
   214      export REGISTRATION_TOKEN=my-registration-token
   215      export REGISTER_NON_INTERACTIVE=true
   216      gitlab-runner register
   217  
   218  To check all possible arguments and environments execute:
   219  
   220      gitlab-runner register --help
   221  
   222  #### Non-interactive registration
   223  
   224  It's possible to use registration in non-interactive / unattended mode.
   225  
   226  You can specify the arguments when invoking the registration command:
   227  
   228      gitlab-runner register --non-interactive <other-arguments>
   229  
   230  Or by configuring the environment variable before the `register` command:
   231  
   232      <other-environment-variables>
   233      export REGISTER_NON_INTERACTIVE=true
   234      gitlab-runner register
   235  
   236  > **Note:** Boolean parameters must be passed in the command line with `--key={true|false}`.
   237  
   238  ### gitlab-runner list
   239  
   240  This command lists all runners saved in the
   241  [configuration file](#configuration-file).
   242  
   243  ### gitlab-runner verify
   244  
   245  This command checks if the registered runners can connect to GitLab, but it
   246  doesn't verify if the runners are being used by the GitLab Runner service. An
   247  example output is:
   248  
   249  ```bash
   250  Verifying runner... is alive                        runner=fee9938e
   251  Verifying runner... is alive                        runner=0db52b31
   252  Verifying runner... is alive                        runner=826f687f
   253  Verifying runner... is alive                        runner=32773c0f
   254  ```
   255  
   256  To delete the old and removed from GitLab runners, execute the following
   257  command.
   258  
   259  >**Warning:**
   260  This operation cannot be undone, it will update the configuration file, so
   261  make sure to have a backup of `config.toml` before executing it.
   262  
   263  ```bash
   264  gitlab-runner verify --delete
   265  ```
   266  
   267  ### gitlab-runner unregister
   268  
   269  This command unregisters registered runners using the GitLab [Runners API](https://docs.gitlab.com/ee/api/runners.html#delete-a-registered-runner).
   270  
   271  It expects either:
   272  
   273  - A full URL and the runner's token.
   274  - The runner's name.
   275  
   276  With the `--all-runners` option, it will unregister all the attached runners.
   277  
   278  NOTE: **Note:**
   279  Runners can be unregistered directly using the GitLab [Runners API](https://docs.gitlab.com/ee/api/runners.html#delete-a-registered-runner) but
   280  configuration will not be modified for the user.
   281  
   282  To unregister a specific runner, first get the runner's details by executing
   283  `gitlab-runner list`:
   284  
   285  ```bash
   286  test-runner     Executor=shell Token=t0k3n URL=http://gitlab.example.com
   287  ```
   288  
   289  Then use this information to unregister it, using one of the following commands.
   290  
   291  >**Warning:**
   292  This operation cannot be undone, it will update the configuration file, so
   293  make sure to have a backup of `config.toml` before executing it.
   294  
   295  #### By URL and token:
   296  
   297  ```bash
   298  gitlab-runner unregister --url http://gitlab.example.com/ --token t0k3n
   299  ```
   300  
   301  #### By name:
   302  
   303  > **Note:** If there is more than one runner with the given name, only the first one will be removed
   304  
   305  ```bash
   306  gitlab-runner unregister --name test-runner
   307  ```
   308  
   309  #### All Runners:
   310  
   311  ```bash
   312  gitlab-runner unregister --all-runners
   313  ```
   314  
   315  ## Service-related commands
   316  
   317  > **Note:** Starting with GitLab Runner 10.0, service-related commands are **deprecated**
   318  and will be removed in one of the upcoming releases.
   319  
   320  The following commands allow you to manage the runner as a system or user
   321  service. Use them to install, uninstall, start and stop the runner service.
   322  
   323  - [gitlab-runner install](#gitlab-runner-install)
   324  - [gitlab-runner uninstall](#gitlab-runner-uninstall)
   325  - [gitlab-runner start](#gitlab-runner-start)
   326  - [gitlab-runner stop](#gitlab-runner-stop)
   327  - [gitlab-runner restart](#gitlab-runner-restart)
   328  - [gitlab-runner status](#gitlab-runner-status)
   329  - [Multiple services](#multiple-services)
   330  - [**Access Denied** when running the service-related commands](#access-denied-when-running-the-service-related-commands)
   331  
   332  All service related commands accept these arguments:
   333  
   334  | Parameter   | Default                                           | Description |
   335  |-------------|---------------------------------------------------|-------------|
   336  | `--service` | `gitlab-runner`                                   | Specify custom service name |
   337  | `--config`  | See the [configuration file](#configuration-file) | Specify a custom configuration file to use |
   338  
   339  ### gitlab-runner install
   340  
   341  This command installs GitLab Runner as a service. It accepts different sets of
   342  arguments depending on which system it's run on.
   343  
   344  When run on **Windows** or as super-user, it accepts the `--user` flag which
   345  allows you to drop privileges of builds run with the **shell** executor.
   346  
   347  | Parameter             | Default               | Description |
   348  |-----------------------|-----------------------|-------------|
   349  | `--syslog`            | `true`                | Specify if the service should integrate with system logging service |
   350  | `--working-directory` | the current directory | Specify the root directory where all data will be stored when builds will be run with the **shell** executor |
   351  | `--user`              | `root`                | Specify the user which will be used to execute builds |
   352  | `--password`          | none                  | Specify the password for the user that will be used to execute the builds |
   353  
   354  ### gitlab-runner uninstall
   355  
   356  This command stops and uninstalls the GitLab Runner from being run as an
   357  service.
   358  
   359  ### gitlab-runner start
   360  
   361  This command starts the GitLab Runner service.
   362  
   363  ### gitlab-runner stop
   364  
   365  This command stops the GitLab Runner service.
   366  
   367  ### gitlab-runner restart
   368  
   369  This command stops and then starts the GitLab Runner service.
   370  
   371  ### gitlab-runner status
   372  
   373  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.
   374  
   375  ### Multiple services
   376  
   377  By specifying the `--service` flag, it is possible to have multiple GitLab
   378  Runner services installed, with multiple separate configurations.
   379  
   380  ## Run-related commands
   381  
   382  This command allows to fetch and process builds from GitLab.
   383  
   384  ### gitlab-runner run
   385  
   386  This is main command that is executed when GitLab Runner is started as a
   387  service. It reads all defined Runners from `config.toml` and tries to run all
   388  of them.
   389  
   390  The command is executed and works until it [receives a signal](#signals).
   391  
   392  It accepts the following parameters.
   393  
   394  | Parameter | Default | Description |
   395  |-----------|---------|-------------|
   396  | `--config`  | See [#configuration-file](#configuration-file) | Specify a custom configuration file to be used |
   397  | `--working-directory` | the current directory | Specify the root directory where all data will be stored when builds will be run with the **shell** executor |
   398  | `--user`    | the current user | Specify the user that will be used to execute builds |
   399  | `--syslog`  | `false` | Send all logs to SysLog (Unix) or EventLog (Windows) |
   400  | `--listen-address` | empty | Address (`<host>:<port>`) on which the Prometheus metrics HTTP server should be listening |
   401  
   402  ### gitlab-runner run-single
   403  
   404  This is a supplementary command that can be used to run only a single build
   405  from a single GitLab instance. It doesn't use any configuration file and
   406  requires to pass all options either as parameters or environment variables.
   407  The GitLab URL and Runner token need to be specified too.
   408  
   409  For example:
   410  
   411  ```bash
   412  gitlab-runner run-single -u http://gitlab.example.com -t my-runner-token --executor docker --docker-image ruby:2.1
   413  ```
   414  
   415  You can see all possible configuration options by using the `--help` flag:
   416  
   417  ```bash
   418  gitlab-runner run-single --help
   419  ```
   420  
   421  You can use the `--max-builds` option to control how many builds the runner will execute before exiting.  The
   422  default of `0` means that the runner has no build limit and will run jobs forever.
   423  
   424  You can also use the `--wait-timeout` option to control how long the runner will wait for a job before
   425  exiting.  The default of `0` means that the runner has no timeout and will wait forever between jobs.
   426  
   427  ### gitlab-runner exec
   428  
   429  > Notice: Not all features of `.gitlab-ci.yml` are supported by `exec`. Please
   430  check what exactly is supported in the [limitations of `gitlab-runner exec`](#limitations-of-gitlab-runner-exec)
   431  section.
   432  
   433  This command allows you to run builds locally, trying to replicate the CI
   434  environment as much as possible. It doesn't need to connect to GitLab, instead
   435  it reads the local `.gitlab-ci.yml` and creates a new build environment in
   436  which all the build steps are executed.
   437  
   438  This command is useful for fast checking and verifying `.gitlab-ci.yml` as well
   439  as debugging broken builds since everything is run locally.
   440  
   441  When executing `exec` you need to specify the executor and the job name that is
   442  present in `.gitlab-ci.yml`. The command should be executed from the root
   443  directory of your Git repository that contains `.gitlab-ci.yml`.
   444  
   445  `gitlab-runner exec` will clone the current state of the local Git repository.
   446  Make sure you have committed any changes you want to test beforehand.
   447  
   448  For example, the following command will execute the job named **tests** locally
   449  using a shell executor:
   450  
   451  ```bash
   452  gitlab-runner exec shell tests
   453  ```
   454  
   455  To see a list of available executors, run:
   456  
   457  ```bash
   458  gitlab-runner exec
   459  ```
   460  
   461  To see a list of all available options for the `shell` executor, run:
   462  
   463  ```bash
   464  gitlab-runner exec shell
   465  ```
   466  
   467  If you want to use the `docker` executor with the `exec` command, use that in
   468  context of `docker-machine shell` or `boot2docker shell`. This is required to
   469  properly map your local directory to the directory inside the Docker container.
   470  
   471  #### Limitations of `gitlab-runner exec`
   472  
   473  With current implementation of `exec` some of the features of GitLab CI will
   474  not work or may work partially.
   475  
   476  We're currently thinking about how to replace current `exec` implementation,
   477  to make fully compatible with all features. Please track [the issue][exec-replacement-issue]
   478  for more details.
   479  
   480  **Compatibility table - features based on `.gitlab-ci.yml`**
   481  
   482  | GitLab CI feature | Available with `exec` | Comments |
   483  |-------------------|-----------------------|----------|
   484  | image             | yes                   | extended configuration (`name`, `entrypoint`) are also supported |
   485  | services          | yes                   | extended configuration (`name`, `alias`, `entrypoint`, `command`) are also supported |
   486  | stages            | no                    | `exec` can only run one job, independently from others |
   487  | before_script     | yes                   | supports both global and job-level `before_script` |
   488  | 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` |
   489  | 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 |
   490  | artifacts         | no                    |          |
   491  | cache             | partially             | Regarding the specific configuration it may or may not work as expected |
   492  | cache:policy      | no                    |          |
   493  | environment       | no                    |          |
   494  | only              | no                    |          |
   495  | except            | no                    |          |
   496  | `allow_failure`   | no                    | `exec` just exits with the result of job; it's callers responsibility to decide if failure is OK or not |
   497  | tags              | no                    |          |
   498  | when              | no                    |          |
   499  | dependencies      | no                    |          |
   500  | coverage          | no                    |          |
   501  | retry             | no                    |          |
   502  | hidden keys       | no                    | If explicitly asked to run, `exec` will try to run such job |
   503  | YAML features     | yes                   | Anchors (`&`), aliases (`*`), map merging (`<<`) are part of YAML specification and are handled by the parser |
   504  | pages             | partially             | Job's script will be executed if explicitly asked, but it doesn't affect pages state, which is managed by GitLab |
   505  
   506  **Compatibility table - features based on variables**
   507  
   508  | GitLab CI feature          | Available with `exec` | Comments |
   509  |----------------------------|-----------------------|----------|
   510  | GIT_STRATEGY               | yes                   |          |
   511  | GIT_CHECKOUT               | yes                   |          |
   512  | GIT_SUBMODULE_STRATEGY     | yes                   |          |
   513  | GET_SOURCES_ATTEMPTS       | yes                   |          |
   514  | ARTIFACT_DOWNLOAD_ATTEMPTS | no                    | artifacts are not supported |
   515  | RESTORE_CACHE_ATTEMPTS     | yes                   |          |
   516  | GIT_DEPTH                  | yes                   |          |
   517  
   518  **Compatibility table - other features**
   519  
   520  | GitLab CI feature | Available with `exec` | Comments |
   521  |-------------------|-----------------------|----------|
   522  | Secret Variables  | no                    |          |
   523  | triggers          | no                    |          |
   524  | schedules         | no                    |          |
   525  | job timeout       | no                    | hardcoded to 1 hour |
   526  | `[ci skip]`       | no                    |          |
   527  
   528  **Other requirements and limitations**
   529  
   530  `gitlab-runner exec docker` can only be used when Docker is installed locally.
   531  This is needed because GitLab Runner is using host-bind volumes to access the
   532  Git sources.
   533  
   534  ## Internal commands
   535  
   536  GitLab Runner is distributed as a single binary and contains a few internal
   537  commands that are used during builds.
   538  
   539  ### gitlab-runner artifacts-downloader
   540  
   541  Download the artifacts archive from GitLab.
   542  
   543  ### gitlab-runner artifacts-uploader
   544  
   545  Upload the artifacts archive to GitLab.
   546  
   547  ### gitlab-runner cache-archiver
   548  
   549  Create a cache archive, store it locally or upload it to an external server.
   550  
   551  ### gitlab-runner cache-extractor
   552  
   553  Restore the cache archive from a locally or externally stored file.
   554  
   555  ## Troubleshooting
   556  
   557  Below are some common pitfalls.
   558  
   559  ### **Access Denied** when running the service-related commands
   560  
   561  Usually the [service related commands](#service-related-commands) require
   562  administrator privileges:
   563  
   564  - On Unix (Linux, OSX, FreeBSD) systems, prefix `gitlab-runner` with `sudo`
   565  - On Windows systems use the elevated command prompt.
   566    Run an `Administrator` command prompt ([How to][prompt]).
   567    The simplest way is to write `Command Prompt` in the Windows search field,
   568    right click and select `Run as administrator`. You will be asked to confirm
   569    that you want to execute the elevated command prompt.
   570  
   571  [exec-replacement-issue]: https://gitlab.com/gitlab-org/gitlab-runner/issues/2797