This integration makes use of GitLab's outgoing webhooks and Mattermost's incoming webhooks to post GitLab events into Mattermost. You can find GitLab's outgoing webhooks described here and Mattermost's incoming webhooks described here.
This integration can be run from any web server that supports Python. The simplest way to get it up and running fast is to use Heroku.
Note: These installation instructions assume you have both a GitLab account with a project you have admin access to, and a Mattermost account where incoming webhooks are enabled.
If you don't already have a Heroku account please go create one here (it's free!).
-
Deploy integration to Heroku
-
Fork the mattermost-integration-gitlab repository on GitHub by clicking Fork in the top-right and selecting your account if it asks.
-
Click the
+
in the top-right corner to add a new app. -
Give your app a name and select your region, then click Create App.
-
On the Deploy screen, select GitHub at the top.
-
Use Connect to GitHub to authorize Herkou to access your GitHub account.
-
Select your account and type
gitlab-mattermost
into the repo-name field, then click Search. -
Click the Connect button next to your repository.
-
Scroll to the bottom of the new page and under the Manual deploy section click Deploy Branch, making sure the
master
branch is selected. -
Go to the Settings tab and under the Domains section copy the Heroku Domain.
-
Set up your GitLab outgoing webhook
-
Log in to your GitLab account, and go to the project you want events pushed from.
-
From your project page, click Settings in the bottom-left and then click Web Hooks. Note that you need have admin access to the project.
-
In the URL field, enter the following
http://<your-heroku-domain>/new_event
. Make sure to replace<your-heroku-domain>
with the domain you copied in the last step of the previous install section. -
Select all the Triggers you want to be posted into Mattermost, then click Add Web Hook.
-
Set up your Mattermost incoming webhook
-
Log in to your Mattermost account, and open your Account Settings by clicking in the top-left.
-
Go to the Integrations tab and click Edit next to Manage your incoming webhooks.
-
Select the channel you want the GitLab events to post to, then click Add.
-
Copy the URL from the newly created webhook.
-
Back on your Heroku app page, go to the Settings tab.
-
Under the Config Variables section, click the Reveal Config Vars button.
-
Enter
MATTERMOST_WEBHOOK_URL
for the KEY and paste the URL you copied as the VALUE, then click Add.
That's it! The integration should now be up and running on Heroku. It might take a minute for the Heroku process to finish starting but after that try performing an action on your GitLab project to trigger a post in Mattermost.
You of course don't have to use Heroku if you don't want to, you can easily set up the integration to run on practically any web server. It can even go behind your firewall as long as the integration still has access to your GitLab and Mattermost instances.
Below are the loose instructions for setting up the integration on a Linux/Ubuntu server.
-
Set up your Mattermost incoming webhook
-
Log in to your Mattermost account, and open your Account Settings by clicking in the top-left.
-
Go to the Integrations tab and click Edit next to Manage your incoming webhooks.
-
Select the channel you want the GitLab events to post to, then click Add.
-
Copy the URL from the newly created webhook and keep it handy for the next steps.
-
Set up your server
-
Stand-up a Linux/Ubuntu server on AWS, your own machine or somewhere else.
-
SSH into the machine, or just open your terminal if you're installing locally.
-
Make sure you have Python 2.7+ installed. If it's not installed you can find it here
python --version
-
Install pip and other essentials
sudo apt-get install python-pip python-dev build-essential
-
Clone the repo with
git clone https://github.com/mattermost/gitlab-mattermost.git
cd gitlab-mattermost
-
Install integration requirements
sudo pip -r requirements.txt
-
Add the following lines to your
~/.bash_profile
export MATTERMOST_WEBHOOK_URL=<your-webhook-url>
This is the URL you copied in the last sectionexport PORT=<your-port-number>
The port number you want the integration to listen on (defaults to 5000)
-
Source your bash profile
source ~/.bash_profile
-
Run the server
python server.py
-
Set up your GitLab outgoing webhook
-
Log in to your GitLab account, and go to the project you want events pushed from.
-
From your project page, click Settings in the bottom-left and then click Web Hooks.
-
In the URL field, enter the following
<your-public-server-domain>/new_event
. Make sure to replace<your-public-server-domain>
with the domain that translates to your public server IP address. Don't forget to include the port if needed. For example,http://myserver.com:5000/new_event
-
Select all the Triggers you want to be posted into Mattermost, then click Add Web Hook.
That's it! The integration should now be running and ready to push GitLab events into Mattermost.