github.com/ssube/gitlab-ci-multi-runner@v1.2.1-0.20160607142738-b8d1285632e6/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  ---
    19  
    20  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
    21  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
    22  **Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*
    23  
    24  - [Using environment variables](#using-environment-variables)
    25  - [Running in debug mode](#running-in-debug-mode)
    26  - [Super-user permission](#super-user-permission)
    27  - [Configuration file](#configuration-file)
    28  - [Signals](#signals)
    29  - [Commands overview](#commands-overview)
    30  - [Registration-related commands](#registration-related-commands)
    31      - [gitlab-runner register](#gitlab-runner-register)
    32          - [Interactive registration](#interactive-registration)
    33          - [Non-interactive registration](#non-interactive-registration)
    34      - [gitlab-runner list](#gitlab-runner-list)
    35      - [gitlab-runner verify](#gitlab-runner-verify)
    36      - [gitlab-runner unregister](#gitlab-runner-unregister)
    37  - [Service-related commands](#service-related-commands)
    38      - [gitlab-runner install](#gitlab-runner-install)
    39      - [gitlab-runner uninstall](#gitlab-runner-uninstall)
    40      - [gitlab-runner start](#gitlab-runner-start)
    41      - [gitlab-runner stop](#gitlab-runner-stop)
    42      - [gitlab-runner restart](#gitlab-runner-restart)
    43      - [gitlab-runner status](#gitlab-runner-status)
    44      - [Multiple services](#multiple-services)
    45  - [Run-related commands](#run-related-commands)
    46      - [gitlab-runner run](#gitlab-runner-run)
    47      - [gitlab-runner run-single](#gitlab-runner-run-single)
    48      - [gitlab-runner exec](#gitlab-runner-exec)
    49      - [Limitations of `gitlab-runner exec`](#limitations-of-gitlab-runner-exec)
    50  - [Internal commands](#internal-commands)
    51      - [gitlab-runner artifacts-downloader](#gitlab-runner-artifacts-downloader)
    52      - [gitlab-runner artifacts-uploader](#gitlab-runner-artifacts-uploader)
    53      - [gitlab-runner cache-archiver](#gitlab-runner-cache-archiver)
    54      - [gitlab-runner cache-extractor](#gitlab-runner-cache-extractor)
    55  - [Troubleshooting](#troubleshooting)
    56      - [**Access Denied** when running the service-related commands](#access-denied-when-running-the-service-related-commands)
    57  
    58  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
    59  
    60  ## Using environment variables
    61  
    62  Most of the commands support environment variables as a method to pass the
    63  configuration to the command.
    64  
    65  You can see the name of the environment variable when invoking `--help` for a
    66  specific command. For example, you can see below the help message for the `run`
    67  command:
    68  
    69  ```bash
    70  gitlab-runner run --help
    71  ```
    72  
    73  The output would be similar to:
    74  
    75  ```bash
    76  NAME:
    77     gitlab-runner run - run multi runner service
    78  
    79  USAGE:
    80     gitlab-runner run [command options] [arguments...]
    81  
    82  OPTIONS:
    83     -c, --config "/Users/ayufan/.gitlab-runner/config.toml"	Config file [$CONFIG_FILE]
    84  ```
    85  
    86  ## Running in debug mode
    87  
    88  Debug mode is especially useful when looking for the cause of some undefined
    89  behavior or error.
    90  
    91  To run a command in debug mode, prepend the command with `--debug`:
    92  
    93  ```bash
    94  gitlab-runner --debug <command>
    95  ```
    96  
    97  ## Super-user permission
    98  
    99  Commands that access the configuration of GitLab Runner behave differently when
   100  executed as super-user (`root`). The file location depends on the user executing
   101  the command.
   102  
   103  Be aware of the notice that is written when executing the commands that are
   104  used for running builds, registering services or managing registered runners:
   105  
   106  ```bash
   107  gitlab-runner run
   108  
   109  INFO[0000] Starting multi-runner from /Users/ayufan/.gitlab-runner/config.toml ...  builds=0
   110  WARN[0000] Running in user-mode.
   111  WARN[0000] Use sudo for system-mode:
   112  WARN[0000] $ sudo gitlab-runner...
   113  ```
   114  
   115  You should use `user-mode` if you are really sure that this is a mode that you
   116  want to work with. Otherwise, prefix your command with `sudo`:
   117  
   118  ```
   119  sudo gitlab-runner run
   120  
   121  INFO[0000] Starting multi-runner from /etc/gitlab-runner/config.toml ...  builds=0
   122  INFO[0000] Running in system-mode.
   123  ```
   124  
   125  In the case of **Windows** you may need to run the **Command Prompt** in
   126  **Administrative Mode**.
   127  
   128  ## Configuration file
   129  
   130  GitLab Runner configuration uses the [TOML] format.
   131  
   132  The file to be edited can be found in:
   133  
   134  1. `/etc/gitlab-runner/config.toml` on \*nix systems when gitlab-runner is
   135     executed as super-user (`root`)
   136  1. `~/.gitlab-runner/config.toml` on \*nix systems when gitlab-runner is
   137     executed as non-root
   138  1. `./config.toml` on other systems
   139  
   140  Most of the commands accept an argument to specify a custom configuration file,
   141  allowing you to have a multiple different configurations on a single machine.
   142  To specify a custom configuration file use the `-c` or `--config` flag, or use
   143  the `CONFIG_FILE` environment variable.
   144  
   145  [TOML]: https://github.com/toml-lang/toml
   146  
   147  ## Signals
   148  
   149  It is possible to use system signals to interact with GitLab Runner. The
   150  following commands support the following signals:
   151  
   152  | Command | Signal | Action |
   153  |---------|--------|--------|
   154  | `register` | **SIGINT** | Cancel runner registration and delete if it was already registered |
   155  | `run`, `exec`, `run-single` | **SIGINT**, **SIGTERM** | Abort all running builds and exit as soon as possible. Use twice to exit now (**forceful shutdown**). |
   156  | `run`, `exec`, `run-single` | **SIGQUIT** | Stop accepting a new builds. Exit as soon as currently running builds do finish (**graceful shutdown**). |
   157  | `run` | **SIGHUP** | Force to reload configuration file |
   158  
   159  ## Commands overview
   160  
   161  This is what you see if you run `gitlab-runner` without any arguments:
   162  
   163  ```bash
   164  NAME:
   165     gitlab-runner - a GitLab Runner
   166  
   167  USAGE:
   168     gitlab-runner [global options] command [command options] [arguments...]
   169  
   170  VERSION:
   171     1.0.0~beta.142.ga8d37f3 (a8d37f3)
   172  
   173  AUTHOR(S):
   174     Kamil TrzciƄski <ayufan@ayufan.eu>
   175  
   176  COMMANDS:
   177     exec		execute a build locally
   178     run		run multi runner service
   179     register	register a new runner
   180     install	install service
   181     uninstall	uninstall service
   182     start	start service
   183     stop		stop service
   184     restart	restart service
   185     status	get status of a service
   186     run-single	start single runner
   187     unregister	unregister specific runner
   188     verify	verify all registered runners
   189     archive	find and archive files (internal)
   190     artifacts	upload build artifacts (internal)
   191     extract	extract files from an archive (internal)
   192     help, h	Shows a list of commands or help for one command
   193  ```
   194  
   195  Below we will explain what each command does in detail.
   196  
   197  ## Registration-related commands
   198  
   199  The following commands allow you to register a new runner, or list and verify
   200  them if they are still registered.
   201  
   202  - [gitlab-runner register](#gitlab-runner-register)
   203      - [Interactive registration](#interactive-registration)
   204      - [Non-interactive registration](#non-interactive-registration)
   205  - [gitlab-runner list](#gitlab-runner-list)
   206  - [gitlab-runner verify](#gitlab-runner-verify)
   207  - [gitlab-runner unregister](#gitlab-runner-unregister)
   208  
   209  The above commands support the following arguments:
   210  
   211  | Parameter   | Default | Description |
   212  |-------------|---------|-------------|
   213  | `--config`  | See the [configuration file section](#configuration-file) | Specify a custom configuration file to be used |
   214  
   215  ### gitlab-runner register
   216  
   217  This command registers your GitLab Runner in GitLab. The registered runner is
   218  added to the [configuration file](#configuration-file).
   219  You can use multiple configurations in a single GitLab Runner. Executing
   220  `gitlab-runner register` adds a new configuration entry, it doesn't remove the
   221  previous ones.
   222  
   223  There are two options to register a Runner, interactive and non-interactive.
   224  
   225  #### Interactive registration
   226  
   227  This command is usually used in interactive mode (**default**). You will be
   228  asked multiple questions during a Runner's registration.
   229  
   230  This question can be pre-filled by adding arguments when invoking the registration command:
   231  
   232      gitlab-runner register --name my-runner --url http://gitlab.example.com --registration-token my-registration-token
   233  
   234  Or by configuring the environment variable before the `register` command:
   235  
   236      export CI_SERVER_URL=http://gitlab.example.com
   237      export RUNNER_NAME=my-runner
   238      export REGISTRATION_TOKEN=my-registration-token
   239      export REGISTER_NON_INTERACTIVE=true
   240      gitlab-runner register
   241  
   242  To check all possible arguments and environments execute:
   243  
   244      gitlab-runner register --help
   245  
   246  #### Non-interactive registration
   247  
   248  It's possible to use registration in non-interactive / unattended mode.
   249  
   250  You can specify the arguments when invoking the registration command:
   251  
   252      gitlab-runner register --non-interactive <other-arguments>
   253  
   254  Or by configuring the environment variable before the `register` command:
   255  
   256      <other-environment-variables>
   257      export REGISTER_NON_INTERACTIVE=true
   258      gitlab-runner register
   259  
   260  ### gitlab-runner list
   261  
   262  This command lists all runners saved in the
   263  [configuration file](#configuration-file).
   264  
   265  ### gitlab-runner verify
   266  
   267  This command checks if the registered runners can connect to GitLab, but it
   268  doesn't verify if the runners are being used by the GitLab Runner service. An
   269  example output is:
   270  
   271  ```bash
   272  Verifying runner... is alive                        runner=fee9938e
   273  Verifying runner... is alive                        runner=0db52b31
   274  Verifying runner... is alive                        runner=826f687f
   275  Verifying runner... is alive                        runner=32773c0f
   276  ```
   277  
   278  To delete the old and removed from GitLab runners, execute the following
   279  command.
   280  
   281  >**Warning:**
   282  This operation cannot be undone, it will update the configuration file, so
   283  make sure to have a backup of `config.toml` before executing it.
   284  
   285  ```bash
   286  gitlab-runner verify --delete
   287  ```
   288  
   289  ### gitlab-runner unregister
   290  
   291  This command allows to unregister one of the registered runners. It expects either
   292  a full URL and the runner's token, or the runner's name. First get the runner's details by
   293  executing `gitlab-runner list`:
   294  
   295  ```bash
   296  test-runner     Executor=shell Token=t0k3n URL=http://gitlab.example.com/ci/
   297  ```
   298  
   299  Then use this information to unregister it, using one of the following commands.
   300  
   301  >**Warning:**
   302  This operation cannot be undone, it will update the configuration file, so
   303  make sure to have a backup of `config.toml` before executing it.
   304  
   305  #### By URL and token:
   306  
   307  ```bash
   308  gitlab-runner unregister --url http://gitlab.example.com/ci/ --token t0k3n
   309  ```
   310  
   311  #### By name:
   312  
   313  > **Note:** If there is more than one runner with the given name, only the first one will be removed
   314  
   315  ```bash
   316  gitlab-runner unregister --name test-runner
   317  ```
   318  
   319  ## Service-related commands
   320  
   321  The following commands allow you to manage the runner as a system or user
   322  service. Use them to install, uninstall, start and stop the runner service.
   323  
   324  - [gitlab-runner install](#gitlab-runner-install)
   325  - [gitlab-runner uninstall](#gitlab-runner-uninstall)
   326  - [gitlab-runner start](#gitlab-runner-start)
   327  - [gitlab-runner stop](#gitlab-runner-stop)
   328  - [gitlab-runner restart](#gitlab-runner-restart)
   329  - [gitlab-runner status](#gitlab-runner-status)
   330  - [Multiple services](#multiple-services)
   331  - [**Access Denied** when running the service-related commands](#access-denied-when-running-the-service-related-commands)
   332  
   333  All service related commands accept these arguments:
   334  
   335  | Parameter | Default | Description |
   336  |-----------|---------|-------------|
   337  | `--service-name` | `gitlab-runner` | Specify custom service name |
   338  | `--config` | See the [configuration file](#configuration-file) | Specify a custom configuration file to use |
   339  
   340  ### gitlab-runner install
   341  
   342  This command installs GitLab Runner as a service. It accepts different sets of
   343  arguments depending on which system it's run on.
   344  
   345  When run on **Windows** or as super-user, it accepts the `--user` flag which
   346  allows you to drop privileges of builds run with the **shell** executor.
   347  
   348  | Parameter | Default | Description |
   349  |-----------|---------|-------------|
   350  | `--service-name`      | `gitlab-runner` | Specify a custom name for the Runner |
   351  | `--working-directory` | the current directory | Specify the root directory where all data will be stored when builds will be run with the **shell** executor |
   352  | `--user`              | `root` | Specify the user which will be used to execute builds |
   353  | `--password`          | none   | Specify the password for the user that will be used to execute the builds |
   354  
   355  ### gitlab-runner uninstall
   356  
   357  This command stops and uninstalls the GitLab Runner from being run as an
   358  service.
   359  
   360  ### gitlab-runner start
   361  
   362  This command starts the GitLab Runner service.
   363  
   364  ### gitlab-runner stop
   365  
   366  This command stops the GitLab Runner service.
   367  
   368  ### gitlab-runner restart
   369  
   370  This command stops and then starts the GitLab Runner service.
   371  
   372  ### gitlab-runner status
   373  
   374  This command prints the status of the GitLab Runner service.
   375  
   376  ### Multiple services
   377  
   378  By specifying the `--service-name` flag, it is possible to have multiple GitLab
   379  Runner services installed, with multiple separate configurations.
   380  
   381  ## Run-related commands
   382  
   383  This command allows to fetch and process builds from GitLab.
   384  
   385  ### gitlab-runner run
   386  
   387  This is main command that is executed when GitLab Runner is started as a
   388  service. It reads all defined Runners from `config.toml` and tries to run all
   389  of them.
   390  
   391  The command is executed and works until it [receives a signal](#signals).
   392  
   393  It accepts the following parameters.
   394  
   395  | Parameter | Default | Description |
   396  |-----------|---------|-------------|
   397  | `--config`  | See [#configuration-file](#configuration-file) | Specify a custom configuration file to be used |
   398  | `--working-directory` | the current directory | Specify the root directory where all data will be stored when builds will be run with the **shell** executor |
   399  | `--user`    | the current user | Specify the user that will be used to execute builds |
   400  | `--syslog`  | `false` | Send all logs to SysLog (Unix) or EventLog (Windows) |
   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  ### gitlab-runner exec
   422  
   423  This command allows you to run builds locally, trying to replicate the CI
   424  environment as much as possible. It doesn't need to connect to GitLab, instead
   425  it reads the local `.gitlab-ci.yml` and creates a new build environment in
   426  which all the build steps are executed.
   427  
   428  This command is useful for fast checking and verifying `.gitlab-ci.yml` as well
   429  as debugging broken builds since everything is run locally.
   430  
   431  When executing `exec` you need to specify the executor and the job name that is
   432  present in `.gitlab-ci.yml`. The command should be executed from the root
   433  directory of your Git repository that contains `.gitlab-ci.yml`.
   434  
   435  `gitlab-runner exec` will clone the current state of the local Git repository.
   436  Make sure you have committed any changes you want to test beforehand.
   437  
   438  For example, the following command will execute the job named **tests** locally
   439  using a shell executor:
   440  
   441  ```bash
   442  gitlab-runner exec shell tests
   443  ```
   444  
   445  To see a list of available executors, run:
   446  
   447  ```bash
   448  gitlab-runner exec
   449  ```
   450  
   451  To see a list of all available options for the `shell` executor, run:
   452  
   453  ```bash
   454  gitlab-runner exec shell
   455  ```
   456  
   457  If you want to use the `docker` executor with the `exec` command, use that in
   458  context of `docker-machine shell` or `boot2docker shell`. This is required to
   459  properly map your local directory to the directory inside the Docker container.
   460  
   461  ### Limitations of `gitlab-runner exec`
   462  
   463  Some of the features may or may not work, like: `cache` or `artifacts`.
   464  
   465  `gitlab-runner exec docker` can only be used when Docker is installed locally.
   466  This is needed because GitLab Runner is using host-bind volumes to access the
   467  Git sources.
   468  
   469  ## Internal commands
   470  
   471  GitLab Runner is distributed as a single binary and contains a few internal
   472  commands that are used during builds.
   473  
   474  ### gitlab-runner artifacts-downloader
   475  
   476  Download the artifacts archive from GitLab.
   477  
   478  ### gitlab-runner artifacts-uploader
   479  
   480  Upload the artifacts archive to GitLab.
   481  
   482  ### gitlab-runner cache-archiver
   483  
   484  Create a cache archive, store it locally or upload it to an external server.
   485  
   486  ### gitlab-runner cache-extractor
   487  
   488  Restore the cache archive from a locally or externally stored file.
   489  
   490  ## Troubleshooting
   491  
   492  Below are some common pitfalls.
   493  
   494  ### **Access Denied** when running the service-related commands
   495  
   496  Usually the [service related commands](#service-related-commands) require
   497  administrator privileges:
   498  
   499  - On Unix (Linux, OSX, FreeBSD) systems, prefix `gitlab-runner` with `sudo`
   500  - On Windows systems use the elevated command prompt.
   501    Run an `Administrator` command prompt ([How to][prompt]).
   502    The simplest way is to write `Command Prompt` in the Windows search field,
   503    right click and select `Run as administrator`. You will be asked to confirm
   504    that you want to execute the elevated command prompt.