Setting up private gitlab server for build automation with event notifications to slack

devops
devops

The purpose of this tutorial is to automate android build generation process using CI tools
like Gitlab CI and send event notifications to slack using webhooks.
We are going to use docker for creating local instance of gitlab server and push a simple
android mobile application to gitlab server running on localhost. All the push events
are monitored by sending push event notifications to slack channel.

Goals:

  1. Deploy gitlab community edition on localhost using docker-compose
  2. Install slack on phone/desktop and connect it to to gitlab instance using webhooks

Prerequisites:

  1. Install docker and docker-compose on your workstation by following the instructions in the following tutorial:
    a)Docker :- https://docs.docker.com/engine/installation/
    b)Docker-compose:- https://docs.docker.com/compose/
  2. Install slack desktop/mobile client:
    https://slack.com/downloads/linux

Steps:

  1. Setup docker compose script for getting docker compose instance up and running:

    I have used the github repo uploaded here: Dockercompose.yml

    You can generate your own session and secret keys using following command in terminal and then add them to above yml file:

  2. Next get Gitlab docker instance up and running using the following command:

  3. Now you sign into gitlab docker instance using gitlab credentials on the following address:

    Gitlab on localhost
    Gitlab on localhost
  4. Now we can push some sample project to gitlab instance. I have pushed a simple android application which I had created earlier.
  5. Next we need to connect slack client to gitlab instance to listen to repo activities and send appropriate alerts to developers on slack channel.
    Headover to slack web version and add web hooks by following the steps in official link below:
    https://docs.gitlab.com/ee/user/project/integrations/slack.html
  6. Once you have completed the setup you should see notifications to your slack channel as follows:

    slack notifications
    slack notifications
  7. Next we can setup Gitlab CI runner to automate build generation process:
    You will have to install gitlab CI on your workstation by following the official documentation:
    Official docs
    Then we need to register the runner on gitlab instance as follows:
    Registration
  8. Next we need to configure runners required as per the project. For example for android applications we can use the following yml file which needs to be added to the root folder of target repo(Android application folder):
    AndroidFile
  9. Once the runner is set up the build process or other scheduled jobs can be configured accordingly within gitlab repo settings.

This concludes today’s tutorial for setting up personal gitlab server instance. You can follow technoetics facebook page to receive updates on upcoming tutorials: TechnoeticsClub

Keep reading and learning new things everyday 😀

Share post-
About Saurabh Mhatre 70 Articles
Currently working in web and hybrid application development