Skip to content

Instantly share code, notes, and snippets.

@aniketmaithani
Last active February 18, 2019 12:28
Show Gist options
  • Save aniketmaithani/cb8438103770400a5179d0ef3144397d to your computer and use it in GitHub Desktop.
Save aniketmaithani/cb8438103770400a5179d0ef3144397d to your computer and use it in GitHub Desktop.

Setup GITLAB

  • Since your GitLab is already setup we'll skip this part. For those interested they can refer to the following doc : Setting Up GitLab

  • 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.abc.com

Make sure you have mapped this instance IP to the domain name in ROUTE53 or any other service that you use.

  • 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

  • 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 order to have execute the runner everytime a code change is pushed please include .gitlab-ci.yml in your project.

Sample gitlab-ci.yml

# 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                                   # Print out python version for debugging
  # Uncomment next line if your Django app needs a JS runtime:
  # - apt-get update -q && apt-get install nodejs -yqq
  - pip install -r requirements/development.txt
test:
  variables:
    DATABASE_URL: "mysql://root:root@localhost:5432/$MYSQL_DB"
  script:
  - py.test
  • For environment variables go to repo-settings and put your env variables/secret there.

Jira Integration :

ref docs : Jira Integration

Slack Integration

ref docs : Slack Integration

THAT'S ALL FOLKS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment