The hook prevents pushing commits with issues that Spectral found.
- Gitlab instance on Linux (Windows not supported)
- Spectral version 1.10.67 and above must be installed on the server: Instructions
All configuration is done through a config file.
- Create a config file in one of the following directories:
.spectral/gitlab-hookdirectory in your home directory, for example
- Add parameters to config (
# file name for log, must be writable by "git" user hook_logfile: /var/log/gitlab/hook.log # optional, but recommended # logging level. For debugging purposes level 6 can be used log_level: 3 # optional, default is 3 (show errors) spectral_dsn: https://firstname.lastname@example.org # REQUIRED # Path to spectral scanner executable. The default is "spectral" # which works if "spectral" binary containing directory is listed in PATH environment variable. # It is required to be installed into your gitlab instance. # For installation instructions under your account at get.spectralops.io press "add sources" , then "use CLI", # then "local repos". spectral_binary: spectral # optional, default is "spectral" # Additional arguments to "spectral history" command, for instance, to exclude some checks. Use with caution! spectral_args:  # optional, array of strings # stop execution after specified number of seconds; child process `spectral` will also be killed exec_timeout: 30 # optional, seconds (int), default is 30 # if this string appears in any of the commit messages being pushed, git hook will skip scanning; # use it with caution when you are sure that commits trigger false positive and ONLY false positive scan results; # likely, you may want to alter the latest commit message with "amend" commit to skip scanning skip_scan_keyword: ~ # string, default "skip-spectral-pre-receive" # gitlab server host url gitlab_host: http://your-own-gitlab-server.com # REQUIRED
- Download the Gitlab pre receive hook.
- Install as a server hook, recommended to install globally for all repositories.
Spectral pre-receive hook allows you to enable the hook logs from the configuration file when the pre-receive hook is triggered.
Before enabling the hook logging, make sure that GitLab logrotate is enabled or custom logrotate that you manage in the server. See gitlab log guide for getting more details.
Spectral pre-receive does not
rotate the file that was written in your Gitlab machine.
In the configuration file (config.yaml) change the
hook_logfile value to
/var/log/gitlab/gitlab-rails (or other path that logrotate is managed and make sure that this path is exists in
logrotate.conf file). To get Gitlab logrotate configuration run the following command:
$ cat /var/opt/gitlab/logrotate/logrotate.conf
You can always change the
log_level value to write more/fewer logs to the file.
3 is the default and indicates an error level, bigger number writes more logging to the file.
log_level field should be empty in the configuration file.
- Added support for .spectral configuration
Updated 26 days ago