Using our Gitlab server for unit testing

gitlab
guide

#1

Our gitlab server has a CI node which is available for you to use to build your projects. If you want it to build your project for you, you need to tell it know to build it.

In the root of your project, create a file named .gitlab-ci.yml, when you push commits to gitlab it will look for the file and if it exists it’ll try to build the project. For full documentation see the Gitlab CI documentation.

There are a couple of reasons you might want to do this over using something like Travis CI on a github project:

  • The whole thing is Free Software
  • Its free to use our CI builder (even for private projects like uni modules)
  • You can have it output artefacts that you can download from your project page
  • Much more control of the build process.
  • Maven builds aren’t broken on our build server :wink:

Maven Example

If you have a Java Maven project the following will build against openjdk-7 and automatically create artefacts for tagged builds. If your like Piers (or are Piers) and you need Java 8 support change the first line to: image: maven:3-jdk-8.

image: maven:3-jdk-7

stages:
    - test
    - deploy
    - cleanup

mvn_test:
    stage: test
    script: "mvn test -B -U"
    except:
        - tags

mvn_package:
    stage: deploy
    script: "mvn package -B -U"
    artifacts:
        paths:
        - target/*.jar
    only:
        - tags

mvn_clean:
    stage: cleanup
    script: "mvn clean -B"
    when: always

Improvements welcome :smile:.

Django Example (Python 2.7)

This one is a bit different because you need to install the dependencies. This one can probably be improved quite a bit but it works as a base.

image: python:2.7-slim

stages:
    - test

django_test:
    stage: test
    script: 
            - apt-get update
            - apt-get install -y gcc gettext postgresql-client libpq-dev sqlite3
            - apt-get install -y python-dev libjpeg-dev libfreetype6-dev zlib1g-dev
            - pip install -r requirements.txt
            - python manage.py test
    except:
        - tags