How to Run Gitlab runners locally
Summary
- Install Docker.
- Setup Gitlab repository and install gitlab-runner.
- Prepare or get the
.gitlab-ci.yml
to test. - Execute a runner on the desired job.
Docker
Install docker
https://docs.docker.com/install/linux/docker-ce/ubuntu/
Don’t forget the post-setup steps.
https://docs.docker.com/install/linux/linux-postinstall/
Setup repository and install gitlab-runner
https://docs.gitlab.com/runner/install/linux-repository.html#installing-the-runner
Prepare or get gitlab-ci.yml
Supposing the following script:
image: "ruby:2.5"
before_script:
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
- ruby -v
- which ruby
- gem install bundler --no-document
- bundle install --jobs $(nproc) "${FLAGS[@]}"
rspec:
script:
- bundle exec rspec
rubocop:
script:
- bundle exec rubocop
there are two jobs defined
- rspec
- rubocop
Execute the runner on a job
in a terminal execute:
gitlab-runner execute docker rspec
this will execute the script in a clean docker the job rspec.
to define a timeout use
--timeout TIME
to pass env variables
--env VAR=VALUE