- Registration-related commands
gitlab-runner register
gitlab-runner unregister
- Service-related commands
- Run-related commands
gitlab-runner exec
- Internal commands
- Troubleshooting
- Gitlab Install With Docker
- Install Docker Gitlab Ci
- Docker Install Gitlab-ce
- Install Docker Gitlab Synology
- Install Gitlab Docker Ubuntu
GitLab Runner contains a set of commands you use to register, manage, andrun your builds.
To create a backup of your repositories and GitLab metadata, follow the backup create documentation. Backup create will store a tar file in /var/opt/gitlab/backups. If you want to store your GitLab backups in a different directory, add the following setting to /etc/gitlab/gitlab.rb and run sudo gitlab-ctl reconfigure. Gitlab-runner exec docker can only be used when Docker is installed locally. This is needed because GitLab Runner is using host-bind volumes to access the Git sources. Internal commands. GitLab Runner is distributed as a single binary and contains a few internal commands that are used during builds. Gitlab-runner artifacts-downloader.
You can check a recent list of commands by executing:
Append --help
after a command to see its specific help page:
Using environment variables
Most of the commands support environment variables as a method to pass theconfiguration to the command.
You can see the name of the environment variable when invoking --help
for aspecific command. For example, you can see below the help message for the run
command:
The output is similar to:
Running in debug mode
Debug mode is especially useful when looking for the cause of some undefinedbehavior or error.
To run a command in debug mode, prepend the command with --debug
:
Super-user permission
Commands that access the configuration of GitLab Runner behave differently whenexecuted as super-user (root
). The file location depends on the user executingthe command.
When you execute gitlab-runner
commands, you see the mode it is running in:
You should use user-mode
if you are sure this is the mode youwant to work with. Otherwise, prefix your command with sudo
:
In the case of Windows, you may need to run the command prompt asan administrator.
Configuration file
GitLab Runner configuration uses the TOML format.
You can find the file to be edited:
- On *nix systems when GitLab Runner isexecuted as super-user (
root
):/etc/gitlab-runner/config.toml
- On *nix systems when GitLab Runner isexecuted as non-root:
~/.gitlab-runner/config.toml
- On other systems:
./config.toml
Most of the commands accept an argument to specify a custom configuration file,so you can have a multiple different configurations on a single machine.To specify a custom configuration file, use the -c
or --config
flag, or usethe CONFIG_FILE
environment variable.
Signals
You can use system signals to interact with GitLab Runner. Thefollowing commands support the following signals:Command | Signal | Action |
---|---|---|
register | SIGINT | Cancel runner registration and delete if it was already registered. |
run , exec , run-single | SIGINT, SIGTERM | Abort all running builds and exit as soon as possible. Use twice to exit now (forceful shutdown). |
run , exec , run-single | SIGQUIT | Stop accepting a new builds. Exit as soon as currently running builds do finish (graceful shutdown). |
run | SIGHUP | Force to reload configuration file. |
For example, to force a reload of a runner’s configuration file, run:
For graceful shutdowns:
killall
or pkill
for graceful shutdowns if you are using shell
or docker
executors. This can cause improper handling of the signals due to subprocessessbeing killed as well. Use it only on the main process handling the jobs.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.
Commands overview
This is what you see if you run gitlab-runner
without any arguments:
Below we explain what each command does in detail.
Registration-related commands
Use the following commands to register a new runner, or list and verifythem if they are still registered.
gitlab-runner register
Parameter | Default | Description |
---|---|---|
--config | See the configuration file section | Specify a custom configuration file to be used |
gitlab-runner register
This command registers your runner in GitLab by using the GitLab Runners API.
The registered runner isadded to the configuration file.You can use multiple configurations in a single installation of GitLab Runner. Executinggitlab-runner register
adds a new configuration entry. It doesn’t remove theprevious ones.
There are two options to register a runner:
- interactive.
- non-interactive.
Interactive registration
This command is usually used in interactive mode (default). You areasked multiple questions during a runner’s registration.
This question can be pre-filled by adding arguments when invoking the registration command:
Or by configuring the environment variable before the register
command:
To check all possible arguments and environments execute:
Non-interactive registration
It’s possible to use registration in non-interactive / unattended mode.
You can specify the arguments when invoking the registration command:
Or by configuring the environment variable before the register
command:
--key={true|false}
.[[runners]]
configuration template file
Additional options can be easily configured during runner registration using theconfiguration template file feature.
gitlab-runner list
This command lists all runners saved in theconfiguration file.
gitlab-runner verify
This command checks if the registered runners can connect to GitLab, but itdoesn’t verify if the runners are being used by the GitLab Runner service. Anexample output is:
To remove the old runners that have been removed from GitLab, execute the followingcommand.
config.toml
before executing it.gitlab-runner unregister
This command unregisters registered runners by using the GitLab Runners API.
It expects either:
- A full URL and the runner’s token.
- The runner’s name.
With the --all-runners
option, it unregisters all the attached runners.
To unregister a specific runner, first get the runner’s details by executinggitlab-runner list
:
Then use this information to unregister it, using one of the following commands.
config.toml
before executing it.By URL and token
By name
All runners
Service-related commands
The following commands allow you to manage the runner as a system or userservice. Use them to install, uninstall, start, and stop the runner service.
All service related commands accept these arguments:Parameter | Default | Description |
---|---|---|
--service | gitlab-runner | Specify custom service name |
--config | See the configuration file | Specify a custom configuration file to use |
gitlab-runner install
This command installs GitLab Runner as a service. It accepts different sets ofarguments depending on which system it’s run on.
When run on Windows or as super-user, it accepts the--user
flag whichallows you to drop privileges of builds run with the shell executor.Parameter | Default | Description |
---|---|---|
--service | gitlab-runner | Specify service name to use |
--config | See the configuration file | Specify a custom configuration file to use |
--syslog | true (for non systemd systems) | Specify if the service should integrate with system logging service |
--working-directory | the current directory | Specify the root directory where all data is stored when builds are run with the shell executor |
--user | root | Specify the user that executes the builds |
--password | none | Specify the password for the user that executes the builds |
gitlab-runner uninstall
This command stops and uninstalls GitLab Runner from being run as anservice.
gitlab-runner start
This command starts the GitLab Runner service.
gitlab-runner stop
This command stops the GitLab Runner service.
gitlab-runner restart
This command stops and then starts the GitLab Runner service.
gitlab-runner status
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.
Multiple services
By specifying the --service
flag, it is possible to have multiple GitLabRunner services installed, with multiple separate configurations.
Run-related commands
This command allows to fetch and process builds from GitLab.
gitlab-runner run
This is main command that is executed when GitLab Runner is started as aservice. It reads all defined runners from config.toml
and tries to run allof them.
The command is executed and works until it receives a signal.
It accepts the following parameters.Parameter | Default | Description |
---|---|---|
--config | See configuration-file | Specify a custom configuration file to be used |
--working-directory | the current directory | Specify the root directory where all data is stored when builds run with the shell executor |
--user | the current user | Specify the user that executes builds |
--syslog | false | Send all logs to SysLog (Unix) or EventLog (Windows) |
--listen-address | empty | Address (<host>:<port> ) on which the Prometheus metrics HTTP server should be listening |
gitlab-runner run-single
This is a supplementary command that can be used to run only a single buildfrom a single GitLab instance. It doesn’t use any configuration file andrequires to pass all options either as parameters or environment variables.The GitLab URL and Runner token need to be specified too.
For example:
You can see all possible configuration options by using the --help
flag:
You can use the --max-builds
option to control how many builds the runner executes before exiting. Thedefault of 0
means that the runner has no build limit and jobs run forever.
You can also use the --wait-timeout
option to control how long the runner waits for a job beforeexiting. The default of 0
means that the runner has no timeout and waits forever between jobs.
gitlab-runner exec
.gitlab-ci.yml
are supported by exec
. Pleasecheck what exactly is supported in the limitations of gitlab-runner exec
section.This command allows you to run builds locally, trying to replicate the CIenvironment as much as possible. It doesn’t need to connect to GitLab, insteadit reads the local .gitlab-ci.yml
and creates a new build environment inwhich all the build steps are executed.
This command is useful for fast checking and verifying .gitlab-ci.yml
as wellas debugging broken builds since everything is run locally.
When executing exec
you need to specify the executor and the job name that ispresent in .gitlab-ci.yml
. The command should be executed from the rootdirectory of your Git repository that contains .gitlab-ci.yml
.
gitlab-runner exec
clones the current state of the local Git repository.Make sure you have committed any changes you want to test beforehand.
For example, the following command executes the job named tests
locallyusing a shell executor:
To see a list of available executors, run:
To see a list of all available options for the shell
executor, run:
If you want to use the docker
executor with the exec
command, use that incontext of docker-machine shell
or boot2docker shell
. This is required toproperly map your local directory to the directory inside the Docker container.
Limitations of gitlab-runner exec
With the current implementation of exec
, some of the features of GitLab CI/CDmay not work or may work partially.
We’re currently thinking about how to replace current exec
implementation,to make it fully compatible with all features. Please track the issuefor more details.
Compatibility table - features based on .gitlab-ci.yml
GitLab CI feature | Available with exec | Comments |
---|---|---|
image | yes | Extended configuration (name , entrypoint ) are also supported. |
services | yes | Extended configuration (name , alias , entrypoint , command ) are also supported. |
before_script | yes | Supports both global and job-level before_script . |
after_script | partially | Global after_script is not supported. Only job-level after_script ; only commands are taken into consideration, when is hardcoded to always . |
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. |
cache | partially | Regarding the specific configuration it may or may not work as expected. |
YAML features | yes | Anchors (& ), aliases (* ), map merging (<< ) are part of YAML specification and are handled by the parser. |
pages | partially | Job’s script is executed if explicitly asked, but it doesn’t affect pages state, which is managed by GitLab. |
GitLab CI feature | Available with exec | Comments |
---|---|---|
GIT_STRATEGY | yes | |
GIT_CHECKOUT | yes | |
GIT_SUBMODULE_STRATEGY | yes | |
GET_SOURCES_ATTEMPTS | yes | |
ARTIFACT_DOWNLOAD_ATTEMPTS | no | Artifacts are not supported. |
RESTORE_CACHE_ATTEMPTS | yes | |
GIT_DEPTH | yes |
GitLab CI feature | Available with exec | Comments |
---|---|---|
Secret Variables | no | |
triggers | no | |
schedules | no | |
job timeout | no | Hardcoded to 1 hour. |
[ci skip] | no |
Gitlab Install With Docker
Other requirements and limitations
gitlab-runner exec docker
can only be used when Docker is installed locally.This is needed because GitLab Runner is using host-bind volumes to access theGit sources.
Internal commands
GitLab Runner is distributed as a single binary and contains a few internalcommands that are used during builds.
gitlab-runner artifacts-downloader
Download the artifacts archive from GitLab.
gitlab-runner artifacts-uploader
Upload the artifacts archive to GitLab.
Install Docker Gitlab Ci
gitlab-runner cache-archiver
Create a cache archive, store it locally or upload it to an external server.
gitlab-runner cache-extractor
Restore the cache archive from a locally or externally stored file.
Troubleshooting
Below are some common pitfalls.
Access Denied when running the service-related commands
Usually the service related commands requireadministrator privileges:
- On Unix (Linux, macOS, FreeBSD) systems, prefix
gitlab-runner
withsudo
- On Windows systems use the elevated command prompt.Run an
Administrator
command prompt.The simplest way is to writeCommand Prompt
in the Windows search field,right click and selectRun as administrator
. You are asked to confirmthat you want to execute the elevated command prompt.
Help & feedback
Docs
Edit this pageto fix an error or add an improvement in a merge request.Create an issueto suggest an improvement to this page.
Show and post commentsto review and give feedback about this page.
Product
Create an issueif there's something you don't like about this feature.Propose functionalityby submitting a feature request.
Join First Lookto help shape new features.
Feature availability and product trials
View pricingto see all GitLab tiers and features, or to upgrade.Try GitLab for freewith access to all features for 30 days.
Get Help
If you didn't find what you were looking for,search the docs.
If you want help with something specific and could use community support,post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLabsubscription).
Docker Install Gitlab-ce
Request supportPlease enable JavaScript to view thecomments powered by Disqus.- Backup and restore Omnibus GitLab configuration
Backup and restore Omnibus GitLab configuration
It is recommended to keep a copy of /etc/gitlab
, or at least of/etc/gitlab/gitlab-secrets.json
, in a safe place. If you everneed to restore a GitLab application backup you need to also restoregitlab-secrets.json
. If you do not, GitLab users who are usingtwo-factor authentication will lose access to your GitLab serverand ‘secure variables’ stored in GitLab CI will be lost.
It is not recommended to store your configuration backup in thesame place as your application data backup, see below.
All configuration for Omnibus GitLab is stored in /etc/gitlab
. To backup yourconfiguration, just run sudo gitlab-ctl backup-etc
. It will create a tararchive in /etc/gitlab/config_backup/
. Directory and backup files will bereadable only to root.
sudo gitlab-ctl backup-etc <DIRECTORY>
will placethe backup in the specified directory. The directory will be created if itdoes not exist. Absolute paths are recommended.To create a daily application backup, edit the cron table for user root:
The cron table will appear in an editor.
Enter the command to create a compressed tar file containing the contents of/etc/gitlab/
. For example, schedule the backup to run every morning after aweekday, Tuesday (day 2) through Saturday (day 6):
You can extract the .tar file as follows.
Remember to run sudo gitlab-ctl reconfigure
after restoring a configurationbackup.
/etc/ssh/
. Be sure to also backup and restore those keys to avoid man-in-the-middle attack warnings if you have to perform a full machine restore.Separate configuration backups from application data
Do not store your GitLab application backups (Git repositories, SQLdata) in the same place as your configuration backup (/etc/gitlab
).The gitlab-secrets.json
file (and possibly also the gitlab.rb
file) contain database encryption keys to protect sensitive datain the SQL database:
- GitLab two-factor authentication (2FA) user secrets (‘QR codes’)
- GitLab CI ‘secure variables’
If you separate your configuration backup from your application data backup,you reduce the chance that your encrypted application data will belost/leaked/stolen together with the keys needed to decrypt it.
Creating an application backup
To create a backup of your repositories and GitLab metadata, follow thebackup create documentation.
Backup create will store a tar file in /var/opt/gitlab/backups
.
If you want to store your GitLab backups in a different directory, add thefollowing setting to /etc/gitlab/gitlab.rb
and run sudo gitlab-ctlreconfigure
:
Creating backups for GitLab instances in Docker containers
Backups can be scheduled on the host by prepending docker exec -t <your container name>
to the commands.
Backup application:
Backup configuration and secrets:
/secret/gitlab/backups
./var/opt/gitlab
for all application data, which includes backups./var/opt/gitlab/backups
(optional). Thegitlab-backup
tool writes to this directory by default.While this directory is nested inside/var/opt/gitlab
, Docker sorts these mounts, allowing them to work in harmony.This configuration enables, for example:
- Application data on regular local storage (through the second mount).
- A backup volume on network storage (through the third mount).
Restoring an application backup
See backup restore documentation.
Backup and restore using non-packaged database
If you are using non-packaged database see documentation on using non-packaged database.
Upload backups to remote (cloud) storage
For details check backup restore document of GitLab CE.
Manually manage backup directory
Omnibus GitLab creates the backup directory set with gitlab_rails['backup_path']
. The directory is owned by the user that is running GitLab and it has strict permissions set to be accessible to only that user.That directory will hold backup archives and they contain sensitive information.In some organizations permissions need to be different because of, for example, shipping the backup archives offsite.
Install Docker Gitlab Synology
To disable backup directory management, in /etc/gitlab/gitlab.rb
set:
Warning If you set this configuration option, it is up to you to create the directory specified in gitlab_rails['backup_path']
and to set permissionswhich will allow user specified in user['username']
to have correct access. Failing to do so will prevent GitLab from creating the backup archive.
Help & feedback
Docs
Edit this pageto fix an error or add an improvement in a merge request.Create an issueto suggest an improvement to this page.
Show and post commentsto review and give feedback about this page.
Product
Create an issueif there's something you don't like about this feature.Propose functionalityby submitting a feature request.
Join First Lookto help shape new features.
Feature availability and product trials
View pricingto see all GitLab tiers and features, or to upgrade.Try GitLab for freewith access to all features for 30 days.
Get Help
If you didn't find what you were looking for,search the docs.
If you want help with something specific and could use community support,post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLabsubscription).