Gitlab CI-CD

September 16, 2018 DevOps 1 minute, 36 seconds

docker run -d --name gitlab-runner --restart always \
  -v /srv/gitlab-runner/config:/etc/gitlab-runner \
  -v /var/run/docker.sock:/var/run/docker.sock \

More install options are available

Run in your runner host (here in the docker container)

sudo gitlab-runner register
  • Get your token from /admin/runners of your Gitlab instance
  • Set your executioner (here docker)
  • No tags, allow untagged jobs, no shared runner (without those settings the runner stuck)

add and push .gitlab-ci.yml in your project root

image: maven:latest

  stage: build
    - mvn verify

  stage: build
    - mvn compile

Recommended: wildcard domain and corresponding SSL certificate

  1. Assign a runner to a group of projects in Gitlab runner
  2. Start runner docker run -d --name gitlab-runner-public --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
  3. Register runner The docker image used can be overwritten in the .gitlab-ci.yml of your pipeline

    1. interactive: docker exec -it gitlab-runner-public bash
      • gitlab-runner register
      • docker as default executioner
      • alpine as default image
    2. or non interactive
      docker run --rm -t -i -v /path/to/config:/etc/gitlab-runner --name gitlab-runner gitlab/gitlab-runner register \
                          --non-interactive \
                          --executor "docker" \
                          --docker-image alpine:3 \
                          --url "" \
                          --registration-token "PROJECT_REGISTRATION_TOKEN" \
                          --description "docker-runner" \
                          --tag-list "docker,aws" \
                          --run-untagged \
  4. Setup Pages (wildcard domain with TLS support) gitlab.rb
            pages_external_url ""
            gitlab_pages['enable'] = true
            gitlab_pages['inplace_chroot'] = true # in case of gitlab-pages daemon not starting due to bind mount permission error
            pages_nginx['redirect_http_to_https'] = true
            pages_nginx['ssl_certificate'] = "/etc/gitlab/ssl/pages-nginx.crt"
            pages_nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/pages-nginx.key"

    Reconfigure and restart

        gitlab-ctl reconfigure
        gitlab-ctl restart gitlab-pages


        # get logs (run in container)
        gitlab-ctl tail gitlab-pages
        # path of your pages (in container)
        ls /var/opt/gitlab/gitlab-rails/shared/pages
        # error log of bundled nginx

Publish static html content with following .gitlab-ci.yml

image: alpine:latest
  stage: deploy
  - echo 'Nothing to do...'
    - public # this is the path in your repo to publish
  - master