Setting up GITLAB Runner on GITLAB Instance

The good thing about being into dev-ops is that you get to learn a lot. Sometimes it’s more sort of revision than being able to JUST ACCOMPLISH A TASK. I have used GITLAB quite a few times but never installed it myself for the staging environment. Here’s a quick start guide with on how to setup GitLab with CI/CD runner on an AWS instance.

Setup GITLAB

  • For those interested they can refer to the following doc : Setting Up GitLab

  • In short take an AMI for GitLab on m2.large instance on AWS. And rest is just plug and play on click of a button.

  • Once GitLab for CI/CD you have to configure the RUNNER.

  • SSH into your system where your GitLab is running.

  • Add GitLab offical repo :

    For Debian/Ubuntu/Mint

    curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash

    For RHEL/CentOS/Fedora

    curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash

  • Install the latest version of GitLab Runner, or skip to the next step to install a specific version:

    For Debian/Ubuntu/Mint

    sudo apt-get install gitlab-runner

    For RHEL/CentOS/Fedora

    sudo yum install gitlab-runner

Register the runner

  • To register runner type

    sudo gitlab-runner register

  • Enter your GitLab instance URL:

    Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com ) https://gitlabs.yoururlwheregitlabisconfigured.com

  • Enter Token for your runner

    Please enter the gitlab-ci token for this runner xxx

  • NOTE : You will find this runner in your admin settings>token. Be very careful in putting the token.

  • Enter a description for the Runner

    Please enter the gitlab-ci description for this runner [hostame] my-runner

  • Enter the tags associated with the Runner, you can change this later in GitLab’s UI:

    Please enter the gitlab-ci tags for this runner (comma separated): my-tag,another-tag

  • After couple of more options of configuration :

  • Enter the runner exectuor [ssh, docker etc.] [Preference : choose docker]

    Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: docker

  • If you chose Docker as your executor, you’ll be asked for the default image to be used for projects that do not define one in .gitlab-ci.yml:

    Please enter the Docker image (eg. ruby:2.1): alpine:latest

  • Once completed you’ll have your runner up and running.

  • In case you are configuring the runner ONLY then in that case you have to download the docker package for your distro.

  • In order to have execute the runner everytime a code change is pushed please include .gitlab-ci.yml in your project.

Sample gitlab-ci.yml

<br /># Official framework image. Look for the different tagged releases at:

# https://hub.docker.com/r/library/python

image: python:latest

# Pick zero or more services to be used on all builds.

# Only needed when using a docker container to run your tests in.

# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service

services: - mysql:latest

# This folder is cached between builds

# http://docs.gitlab.com/ce/ci/yaml/README.html#cache

cache: paths: - ~/.cache/pip/

# This is a basic example for a gem or script which doesn't use

# services such as redis or postgres

before_script: 
- python -V 
- pip install -r requirements/development.txt 
test: variables: DATABASE_URL: "mysql://root:root@localhost:5432/$MYSQL_DB" 
script:
    - flake8 
    - py.test    
  • For environment variables go to repo-settings and put your env variables/secret there.

    Jira Integration :

    ref docs : ![Jira Integration][2]

    Slack Integration

    ref docs : ![Slack Integration][3]

    THAT’S ALL FOLKS

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>