Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Services can be combined in Gitlab CI by specifying the services required for a particular job or stage through the "services" keyword.

For example, to combine a PostgreSQL database service with a Ruby on Rails application, you can define the following configuration in your ".gitlab-ci.yml" file:

services:
  - postgres:latest

stages:
  - test

rspec:
  image: ruby:2.5
  script:
    - bundle install --jobs "$(nproc)" --retry 5
    - bundle exec rails db:create db:migrate RAILS_ENV=test
    - bundle exec rspec

In this example, the "postgres" service is specified as a dependency for the "rspec" job, which requires a running PostgreSQL instance to execute the tests. By doing so, Gitlab CI automatically starts the PostgreSQL container before running the "rspec" job, and links the container to the job's image so that the Rails application can access the database.

Other services can also be added in the same way, for example, a Redis cache or Elasticsearch index, depending on your application's requirements.