Thursday, January 12, 2017

Setting up a GitLab Specific runner on CentOS

In this post, I'll list the steps which I followed to configure a GitLab runner on the same host where GitLab server is running.

What are Runners in GitLab?
You can run builds on your merge request or after push in GitLab. Traditionally we used to run builds on a separate CI server like Jenkins. But though GitLab is a Git repository, it is more than that. The 'Runners' are the virtual machine on which GitLab CI runs your build.

My GitLab host environment

  • GitLab v8.15.4 EE deployed on AWS
  • OS: CentOS 7.2

Creating a Runner

  • Install docker
    • If you want GitLab to run your builds inside a docker container, you need to install docker

      • curl -fsSL https://get.docker.com/ | sh
      • This script adds the docker.repo repository and installs Docker.
      • sudo systemctl enable docker.service
        • Enable the service
      • sudo systemctl start docker
        • Start the Docker daemon
      • Verify docker is installed correctly by running a test image in a container.
        • sudo docker run --rm hello-world
  • Add GitLab's official repository via Yum
    • curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash
  • Install gitlab-ci-multi-runner
    • sudo yum install gitlab-ci-multi-runner
  • Register the runner
    • sudo gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://127.0.0.1/ci
Please enter the gitlab-ci token for this runner
WKC4P9FuurUtQZ4h2xCH
Please enter the gitlab-ci description for this runner
master-runner
INFO[0034] fcf5c619 Registering runner... succeeded
Please enter the executor: shell, docker, docker-ssh, ssh?
docker
Please enter the Docker image (eg. ruby:2.1):
ruby:2.1
INFO[0037] Runner registered successfully. Feel free to start it, but if it's
running already the config should be automatically reloaded!
    • I wanted my runner to run the same host where GitLab is running and hence I entered https://127.0.0.1/ci for the gitlab-ci coordinator URL
    • To get the gitlab-ci token, browse to
      • Project -> Settings wheel -> Runners -> Specific Runners -> Use the following registration token during setup: WKC4P9FuurUtQZ4h2xCH
  • Verify that Runner is successfully activated
    • Project -> Settings wheel -> Runners -> Runners activated for this project -> You should see a green colour runner

Verifying runners with command line

  • gitlab-runner list
    • List the registered runners
  • gitlab-runner verify
    • This command checks whether registered runners can connect to GitLab server
  • Unregister
    • gitlab-runner unregister --url http://127.0.0.1/ci --token ajsbgjav
    • or
    • gitlab-runner unregister --url http://127.0.0.1/ci --name master-runner

Reference

2 comments:

DevOps Online Training in Hyderabad said...

Thanks for sharing an easy setup guide for Gitlab, this is so useful to DevOps candidates a lot. Keep up the great work.

Best Regards,
CourseIng - DevOps Training in Hyderabad

rajani said...

Nice Blog!! I like it and thanks for sharing that wonderful information.Thankyou.
DevOps Training
DevOps Online Training