Tutorial: Trigger Notifications when your Code is Deployed
Tags: python, tutorial, github, beginners
Published: 2020-04-24 17:33:40

*Happy Friday everyone. If you have questions about this tutorial, please drop me a comment.*

##Introduction
Keeping your team informed about the status of your site is important, but can be hard to keep track of. Why not build an automated system that notifies you about these sorts of changes? In this tutorial, let's take a look at how we can send our team a notification whenever our code is deployed.

##Prerequisites
No prerequisites but some content you might find helpful:
[Working with Python](https://docs.wayscript.com/library/modules/python)
[Working with Slack](https://docs.wayscript.com/library/modules/python)
[Working with the GitHub trigger](https://docs.wayscript.com/library/triggers/github-trigger)

##Recap of Terminology
While developers will likely not need the recap, here's some terminology we'll use throughout this tutorial just in case:
<ul><li>*Production Environment* - Configurations/Settings of where your software is used by end users.
<li>*Stable Branch* - The branch of your code deployed to your production environment
<li>*Master Branch* - Branch which may contain new tested features, will be merged into the stable branch to be deployed to the production environment.
<li>*Staging Branch* - Branch which contains new untested features, deployed to staging environment to be tested by developers.
<li>*Other Branches* - Developers build new features onto their created branches before merging to staging for testing.</ul>

##Notifying Upon Stable Branch Push
To send these notifications, there's a couple of different ways to do this. We are making the assumption here that your stable branch, once merged, will be automatically deployed. If this isn't the case, then you are still able to create notifications through WayScript with the use of the Python module. Of course, depending on your server provider, these specific API calls will vary.

With automatic deployments enabled, this notification script becomes very easy to make. The first thing we need to do, is to create a script and place in a [GitHub Trigger](https://docs.wayscript.com/library/triggers/github-trigger).

![GitHub Trigger](https://cdn.wayscript.com/blog_img/79/1.png)

This trigger allows us to activate events in our script whenever certain actions happen in our denoted repo.

![trigger](https://cdn.wayscript.com/blog_img/79/2.png)

For us, since we want to notify our team whenever a push event happens to our staging branch, we can do this by selecting the push event type, then choosing the branch.

![choosing branch](https://cdn.wayscript.com/blog_img/79/3.png)

##Notification of Push
Once this push occurs, this activates everything below this trigger in our workflow. We can add many different notification sources to occur. Let's use slack:

![Slack](https://cdn.wayscript.com/blog_img/79/4.png)

Once we add slack, we configure it to the desired channel to post the notification to. We also denote the message we want to send:

![Message send](https://cdn.wayscript.com/blog_img/79/5.png)

##Example of the Completed Script
That's it for this one! Not many moving parts to explain. If you would like to view this script yourself, or clone it to your own WayScript account, you can find it [here](https://wayscript.com/user/derricks/rs2bIuem).