Automated Notification and Testing with Buddy
Tags: devops, beginners, webdev, softwareengineering
Published: 2020-12-29 05:29:43

---
title: Automated Notification and Testing with Buddy
published: true
date: 2020-07-21 23:26:42 UTC
tags: Devops,beginner,WebDevelopment,SoftwareEngineering
canonical_url: https://lo-victoria.com/automated-notification-and-testing-with-buddy
---

Hello and welcome back to 3rd article of [The DevOps Series with Buddy](https://hashnode.com/series/the-devops-series-with-buddy-ckbut97o9002nwus16xjmgt80)!

In the previous articles, [Introduction to DevOps](https://lo-victoria.com/introduction-to-devops-with-buddy) and [Managing Team and Roles](https://lo-victoria.com/managing-team-and-roles-with-buddy), we have explored the following concepts:
- What is DevOps?
- What is CI/CD?
- What is a pipeline?
- What are the DevOps Team Structures and Roles?
- How do we manage roles and permissions in Buddy?

For this article, we shall discuss another important concept in DevOps: **Automation**

## Automation in DevOps is Crucial. Here's Why.
Previously in the [Introduction to DevOps](https://lo-victoria.com/introduction-to-devops-with-buddy-ckc86jas80080ups179d51nbg) article, I have explained what a CI/CD Pipeline is. To recap, it is essentially a **fully automated and efficient** pipeline to continuously test and deliver high-quality products to the user.

![DevOps-Workflow.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1594411090612/Jfn2WhudO.png)

Automation in the pipeline can help developers perform tests more frequently without much manual labour and time. It helps speed up communication as well to have automated notifications sent to the team when there is an error or bug fixed in the pipeline.

Having automation is crucial for DevOps because it achieves the following:
- Continuous integration
- Continuous testing
- Continuous monitoring
- Continuous deployment
- Continuous delivery

**'Continuous'** is a keyword here. It means little to no time is wasted on having to do these tasks manually and that it is routinely performed. 
All key processes in the workflow are streamlined and optimized. 

![maqs_at_a_glance.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1594411158328/oC88gc6Co.jpeg)

With automation, a single push to a code branch can trigger the pipeline to process all its actions automatically. Then, in the event of an error, it will immediately notify team members for instant monitoring and debugging.

## Implementing Automated Notifications with Buddy
[Buddy CI/CD](https://buddy.works?utm_source=devops_with_buddy&utm_medium=referral&utm_campaign=content_victoria_lo) allows you to add notification actions into your CI/CD pipeline in the simplest way! If you haven't created a Buddy account, go to [buddy.works](https://buddy.works?utm_source=devops_with_buddy&utm_medium=referral&utm_campaign=content_victoria_lo) to set up an account.

Read the [first article](https://lo-victoria.com/introduction-to-devops-with-buddy-ckc86jas80080ups179d51nbg) to learn more on how to get started with Buddy.

### **Step 1: Add an Action**
Go to your Pipeline > Actions just like the image below:

![1.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594412563387/3FF6PH7cl.png)

Then, click on the '+' icon under Primary Actions to add a new action before or after an action. In my case, I will add the notification action after the **'firebase deploy'** action.

Note: The sequence of actions the pipeline will execute in top-down order.

### **Step 2: Select a Notification Action**
Scroll down to Notification section and select the communication medium your team uses. As seen in the image below, Buddy conveniently provides common channels like Slack and Discord while also providing traditional forms of communication like SMS and email.

![2.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594413448059/HlNlS_LYV.png)

For this example, I shall add an **Email** notification action to my pipeline.

### **Step 3: Configure Notification**
Now we can set up our notification. For an email, we can configure the Sender, Subject, Email Body and Recipients. 

By default, the Sender is Buddy and Subject is the pipeline's name and execution ID, represented using Buddy's [Environment Variables](https://buddy.works/docs/pipelines/environment-variables?utm_source=devops_with_buddy_docs&utm_medium=referral&utm_campaign=content_victoria_lo#default-environment-variables).

![email.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594910712375/JAUlnPYNt.png)

After configuring the details, don't forget to **save the action** and it will show up in your pipeline like so:

![2.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594414417593/a6_o82tYj.png)


#### About Environment Variables
In Buddy, environment variables (or ENV VARs) are key-value pairs that can be used in pipelines without manually updating their values. Upon every pipeline execution, Buddy will automatically populate ENV VARs with their respective values. This saves plenty of time for developers, reduce human errors and risks of having sensitive information revealed.

For example, in our Email Notification, our Subject contains 2 ENV VARs: **$BUDDY_PIPELINE_NAME** and **$BUDDY_EXECUTION_ID**, which represents the pipeline name and ID. 

More examples of these variables in Buddy are:

![env_var.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594911084176/bjyoS5PoC.png)

For more information, visit the [Environment Variables](https://buddy.works/docs/pipelines/environment-variables?utm_source=devops_with_buddy_docs&utm_medium=referral&utm_campaign=content_victoria_lo#default-environment-variables) page at Buddy.


### **Step 4: Run Pipeline**
Now we can test if the notification action is working by running the pipeline! If there are no errors, we should see the following email in our inbox:

![8.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594414517541/f5IBxDqMN.png)

Cool! We have implemented our notification action successfully. Every time we run the pipeline, this email would be sent to the specified recipient emails. This is helpful for team members to monitor pipeline executions in the project.

#### Conditional Notifications
To take it a step further, we can have notification actions that only run when there is an error in the pipeline. 

To do this, simply add the same Email notification action under the **'Actions Run on Failure'** section, below 'Primary Actions'. 

![5.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594419655983/MhGJtMVn9.png)

Then set the Subject and Email Body to indicate that this is an error notifying email. We can add the environment variable **$BUDDY_FAILED_ACTION_LOGS** to the Email Body to automatically include the error logs in the email. It is a very helpful feature for efficient team communication and progress monitoring!

![3.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594911475437/YS_IFBxB9.png)

More conditional notifications can be set under the **'Condition'** tab of the action. These conditions include:
- Changes in the repository since last execution
- Changes to specific paths in the repository since last execution
- If an environment variable has a specific value
- A specified date and time
- A specified pipeline pass with the same revision

![7.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594416018073/cAFJY6HZU.png)

## Implementing Automated Testing with Buddy
Now that we have implemented automated notifications in our pipeline, let's include an automated testing action too!

#### Buddy's Testing Actions
What makes Buddy exceptional at automation is its wide variety of testing tools that includes:
- [Daily Integration tests](https://buddy.works/docs/pipeline-examples/daily-integration-tests?utm_source=devops_with_buddy_docs&utm_medium=referral&utm_campaign=content_victoria_lo)
- [Pull requests tests](https://buddy.works/docs/pipeline-examples/pull-request-testing?utm_source=devops_with_buddy_docs&utm_medium=referral&utm_campaign=content_victoria_lo)
- [Selenium tests](https://buddy.works/docs/pipeline-examples/selenium-tests?utm_source=devops_with_buddy_docs&utm_medium=referral&utm_campaign=content_victoria_lo)
- [Unit tests (i.e. Mocha/Chai)](https://buddy.works/guides/how-automate-nodejs-unit-tests-with-mocha-chai?utm_source=devops_with_buddy_guides&utm_medium=referral&utm_campaign=content_victoria_lo)

For more information of Unit Testing with Mocha and Chai, you may read my article on the topic [here](https://lo-victoria.com/introduction-to-unit-testing-with-mocha-and-chai-ckbqjbqqm00s3lgs14w34pdgq).

### **Step 1: Add an Action**
Same as before, go to your Pipeline > Actions and add a new action by clicking the '+' icon before or after an action.

For my example, I'm adding an **ESLint** action to test and fix any JavaScript code violations before deploying my app to Firebase. I will show you how to use more testing tools with Buddy in the future articles of this series.

![4.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594416820745/6-HUzyIVd.png)

### **Step 2: Configure Action**
For this ESLint action, I'm keeping the settings to their default values.

![6.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1594417222676/QS9BQ-ks1.png)

Click **'Add this action'** and it will be added to the pipeline.

For more details on each settings in the ESLint action, read the documentation [here](https://buddy.works/docs/yaml/yaml-actions/eslint?utm_source=devops_with_buddy_docs&utm_medium=referral&utm_campaign=content_victoria_lo).

Here's an overview of our pipeline and its actions:

![1.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1595341903347/FCUzL430O.png)

### **Step 3: Run Pipeline**
Now let's try running the pipeline to check for errors in our code with our newly added ESLint action. Unfortunately, it looks like my code do have some errors so the pipeline will immediately stop running and send the error notification email under the conditional execution.

![2.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1595342020543/8u9Z3CJE8.png)

Here's what I found in my inbox:

![error.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1594911469029/Ln1IANTwu.png)

As seen in my example, my code has a lot of errors and so the conditional email notification we implemented earlier will be sent to notify the team member that an error has occurred in the pipeline. It's all automatic and very convenient!


## Next Steps
Congratulations! You have learned how automation is crucial for DevOps and how it can be implemented. This simple example serves to demonstrate the simplicity and flexibility of how [Buddy CI/CD](https://buddy.works?utm_source=devops_with_buddy&utm_medium=referral&utm_campaign=content_victoria_lo) can easily implement notifications and testing into your pipeline. I hope this article has been helpful in introducing the types of automation processes (i.e. notification and testing) that can integrated into your CI/CD pipeline.

Of course, there are countless useful [actions](https://buddy.works/actions?utm_source=devops_with_buddy_actions&utm_medium=referral&utm_campaign=content_victoria_lo) you can add to further automate your pipeline. I'll write more testing actions in future articles so stay tuned! Please visit [buddy.works](https://buddy.works?utm_source=devops_with_buddy&utm_medium=referral&utm_campaign=content_victoria_lo) or read their documentation [here](https://buddy.works/docs?utm_source=devops_with_buddy_docs&utm_medium=referral&utm_campaign=content_victoria_lo) to learn more.

In the next few articles of this series, I'll be showing you how to implement more automated testing and how to deploy your apps on various platforms like heroku and Netlify! Till next time, cheers!