The quickest way to integrate Mattermost into your GitLab release pipeline

Organizing a software release is a cross-team effort and a large undertaking. Leveraging the power of Mattermost Playbooks can help your team stay on deadline and keep confusion at bay. In this post, we’ll learn how to quickly integrate Mattermost into your GitLab release pipeline to help streamline your release processes.

At the end of the blog post, there’s a link to a release management demo that you can try out in the browser to see these ideas in action. With these tips under your belt, you’ll be able to replicate the success in your own release processes.

Setting up a playbook for release management

To get started, create a Playbook from either the Product Release template or the blank template. The pre-built release management template has a general release flow and suggests some ways you might want to incorporate your process, but starting from a blank template and incrementally building what you need is also an effective approach, depending on the scale of your release process.

The playbook can be edited within each run in real-time, so think of this checklist as a living document that you can adapt on the fly. For that reason, don’t get stuck thinking about every situation upfront. You can start from a very simple process and scale up as you discuss new discrete tasks that need to be replicated each time.

Because you’re using Playbooks, each release management run will keep all related team messages in its one dedicated channel. When coordinating between teams to release software, this ad hoc and contextualized channel is a great way to immediately put everyone in one spot and assign an appropriate agenda.

Gone are the days of wondering what’s going on or what needs to be done and by whom. The Playbook will organize all of that information so everyone is on the same page. You’ll also be able to add participants and stakeholders on the fly, depending on the situation at hand.

Extending your playbook with slash commands

But organizing people and messaging for a shared purpose is only one part of the challenge. You must also equip the team with the tools they need for the task at hand. By creating slash commands easily in the Integrations menu, you can add clickable buttons to your playbooks that trigger any webhook process. Similarly, you can configure inbound webhooks or add popular plugins and apps (more on that in a moment).

When dealing with release management, you can leverage our maintained GitLab and GitHub plugins to communicate with your source control within Mattermost. With them, you can run pipelines, open and track issues, review PRs, and receive notifications. Because their functionality can be executed via slash commands, you can add them to your Playbook checklist to become a button.

If you combine this approach with a cloud developer workspace (like Gitpod), you can spin up ephemeral developer environments for each situational Playbook run. Now you’re isolating distractions and making it easy to jump into troubleshooting, and this is where using Playbooks for release management truly shines.

By creating your personalized toolbox of slash commands, you can build complex but repeatable workflows with Playbooks.

Level up your Playbook with a release management back-end

To create deeply customized slash commands and workflows with rich responses, you can host your own backend to ingest webhooks and query external APIs. This demo was built in Node and uses hapi as the web server. I set up an API on the route api/v1/<endpoint> and hosted the server where Mattermost could reach it. From here, I added endpoints for each slash command I wanted in my Playbook and set up those corresponding slash commands on Mattermost. For example, I made the /ping command and the /gitpod command which are used in the Playbook. Each slash command request handler can have its own logic with this approach. After they’re done with my custom workflow, they can send a Markdown message in response to the slash command by returning the following body:

return {
        response_type: "in_channel",
        text: `Access your Gitpod cloud workstation: https://gitpod.io/#https://gitlab.com/andrew.zigler/mattermonsters/-/tree/${request.payload.user_name}/\n\n⚛️ The React project will automatically start building and will open once it's ready. **After that happens, come back here and follow the next step.**`,
      }

They can also return rich message attachments. But what if your slash command needs to ping some external APIs and wait for unpredictable return-trip time on those requests? Or what if you need to do a task that simply requires patience before it’s completed? In this case, you risk the webhook response timing out and the Mattermost server thinking it failed. To notify that the webhook is being processed, you can respond immediately with an ephemeral message:

return {
        response_type: "ephemeral",
        text: "Merging, please wait...",
      }

Then when you’re ready to notify the channel of the results, you can use the responseUrl inside the request’s payload as the destination to POST the response:

await fetch(responseUrl, {
            method: "POST",
            body: `The \`${feature}\` branch was successfully merged. Don't forget to pull down your changes on Gitpod!`,
          })

This approach is as scalable as you intend it to be. Be mindful of the best way to implement these pipeline workflows into your release management Playbooks by leveraging pre-existing resources. If you find that all of your desired slash command actions are source control-related, you could also leverage GitLab’s slash commands to do things like run CI/CD pipelines. Check out their documentation for more details.

Instead of doing all of this on your own server, you could also use a cloud integration tool like Pipedream to create serverless workflows with a drag-and-drop interface of code blocks. This can take the hassle out of hosting your own server and streamline the process.

Where to go with Playbooks from here

Now that you’ve read about using Mattermost Playbooks for release management, it’s time to try it out for yourself. Follow this link and create an account on the Mattermost server to experience a release management Playbook for yourself, try out some real working slash commands, and release your own Mattermonster into the wild!

And now that you’ve seen Playbooks in action for release management, you might also be considering other ways you can use Playbooks in your software development lifecycle. There are other templates included as well, including one for bug bashing. If you use Playbooks to bug bash each release, it will make your workflow more uniform and you can re-use slash commands and insights between playbooks!

Andrew Zigler is a developer advocate at Mattermost and public speaker at the intersection of AI and open source technologies. After studying Classics at The University of Texas at Austin and later teaching English in Japan, he continues to champion career and technical education for his audience.