Cozmo, IFTTT and Jenkins Build Notifications

CozmoJenkins.png

Recently I bought Anki Cozmo. This little tiny robot is amazing and a great companion on your desk. Cozmo comes with a great personality. He is full of fun, he plays games with you, do tricks, animate and makes a lot of joy. Cozmo comes with a Camera that can detect faces and greet people and pets. It also has a SDK which allows you to customize Cozmo and create cool Apps and IoT connected programs.

In this post, I’ll show how to use Cozmo with my Jenkins IFTTT Build Notification plugin to send build notification to Cozmo. He will animate to these notifications and do some tricks like lighting up his cubes. This will make Cozmo an eXtreme Feedback Device

The Cozmo SDK comes with a bundle of examples and apps that you can play and modify. There is a bunch of examples that connect Cozmo to IFTTT and use different channels like Gmail or Sports news. I took the Gmail example and modified it to get Jenkins notifications. Here’s how this works on a high level:

Cozmo.png

Step 1 – Connecting Cozmo from IFTTT

In order to connect Cozmo from IFTTT, we need a computer running Cozmo exposed to the internet. You can do this either by using a static IP or using a tool like ngrok which sets up a secure tunnel to localhost running on your computer. To set up ngrok follow instructions from https://ngrok.com/download

Run this command to create a secure public URL for port 8080:

 ./ngrok http 8080 

Note the HTTP forwarding address shown in the terminal (e.g., http://4916890d.ngrok.io). This is required while creating the IFTTT applet.

ngrok.png

WARNING: Using ngrok exposes your local web server to the internet. See the ngrok   documentation for more information: https://ngrok.com/docs

Step 2 – IFTTT Jenkins Cozmo Script

Cozmo SDK is presently available in Python. The IFTTT examples use aiohttp module to create a web server with an endpoint with a handler to call the Cozmo SDK:

Complete source code is available at https://github.com/upgundecha/cozmo-python-sdk

Step 3 – Creating IFTTT Recipe

IFTTT is a web service that lets you create chains of simple conditional statements, called applets. An applet is triggered by changes that occur within other web services such as Gmail, Facebook, Instagram, or Twitter. An applet may send an e-mail message if the user tweets using a hashtag or copy a photo on Facebook to a user’s archive if someone tags a user in a photo or it can trigger an support IoT device to a specific action.

In this example, we will create custom IFTTT Trigger and Action using Maker Webhooks feature.

  1. Sign up and sign into https://ifttt.com
    1. Create an applet: https://ifttt.com/create
    2. Set up your trigger.
      1.         Click “this”.
      2.         Select “Maker Webhooks” as your service.
      3.         Under “Choose a Trigger”, select “Receive a Web request”.
      4.         In “Receive a Web Request”, enter “JenkinsBuild” as “Event Name”
      5.         Click “Create Trigger” button
    3.     Set up your action.
      1.        Click “that”.
      2.        Select “Maker Webhooks” to set it as your action channel. Connect to the Maker channel if prompted.
      3.        Click “Make a web request” and fill out the fields as follows. Remember your publicly accessible URL from above (e.g., http://55e57164.ngrok.io) and use it in the URL field, followed by “/iftttJenkins” as shown below:

URL: http: // 55e57164.ngrok.io / iftttJenkins
Method: POST
Content Type: application / json
Body: {“project”: “{{Value1}}”, “build”: “{{Value2}}”, “status”: “{{Value3}}”

Click “Create Action” then “Finish”.

Here is video loop for above settings:

ifttt_maker.gif

Step 4 – Configuring Jenkins Build Job

Setup Jenkins Job – requires IFTTT Build Notification Plugin

In Jenkins job “Post-build Action” section add a new “IFTTT Build Notifier” action with following values:

  1. Event Name: JenkinsBuild
  2. Key: <Make Webhooks Key>

Note: You can get your unique Maker Webhooks Key from https://ifttt.com/services/maker_webhooks/setting

Finally, run the Jenkins job to test the setup. In response to the ifttt web request, Cozmo should roll off the charger, raise and lower his lift, announce the status, and then animate and light-up the cubes.

Here is video loop for above settings:

jenkins.gif

Running it together

Here’s video with Cozmo’s reaction to a passed build vs. a failed build:

You can also connect CI tools like Travis or Circle CI using curl command to Maker endpoint.
We can add more actions to this web server and make Cozmo thrill.

API Testing with Postman Collections in AWS CodePipeline

This post explains how to setup an AWS CodePipeline to run Postman collections for testing REST APIs using AWS CodeCommit and AWS CodeBuild.

Step 1 – Creating a Git repository with AWS CodeCommit

AWS CodeCommit is a version control service hosted by AWS. You can create, manage Git repositories on CodeCommit.

For this project, we will create a new repository named postman-sample from AWS Console > Developer Tools > CodeCommit

Picture1.png

Clone the newly created repository on your computer

Step 2 – Exporting Postman Collection

Next, we need to export the Postman collection so we can run this using newman cli

Picture2.png

Select Collection v2 option from Export Collection dialogue box and click Export

Picture3.png

Save the collection in cloned repository folder from Step 1 above

Creating buildspec file

We need to create a buildspec file to tell AWS CodeBuild how we want to run the collection. Before running the collection we need to install newman npm package in pre_build phase and then call newman cli with the collection we want to run in the build phase. We can also specify report options to generate HTML file at the end. We will upload this file to S3 after CodeBuild executes the collection:

Picture5.png

Commit & Push the collection and buildspec file to CodeCommit in master branch

You can find the collection and buildspec file used for this example at https://github.com/upgundecha/postman-sample

Step 3 – Creating an S3 Bucket to save report

Let’s create an S3 bucket to save the report file generated by the newman. We can use this file to publish the results.

From AWS Console > Storage > S3 create a new bucket named postmanreport (you will need to use a unique name). You can enable version control on S3 bucket to see historical reports.

Picture6.png

Step 4 – Creating an AWS CodeBuild Project

We will use CodeBuild to fetch the changes from CodeCommit and run the collection using newman. We already have buildspec file which has a sequence for execution.

From AWS Console > Developer Tools > CodeBuild create a project named postman-sample.

Set Source Provider as AWS CodeCommit and Repository as postman-sample:

Picture8.png

We need an environment to run the build job. Let’s configure the Ubuntu/Node.js environment and Artefacts settings as shown in below screenshot:

Picture9.png

Next, we need to configure a Service role. Create a new service role and click Continue

Picture10.png

The CodeBuild project is ready. We can test this project by manually starting the build.

Picture11.png

Step 5 – Bringing it together with AWS CodePipeline

Finally, we need to create a new AWS CodePipleine to trigger the CodeBuild when a new change is pushed to CodeCommit.

From AWS Console > Developer Tools > CodePipeline create a pipeline named postman-sample:

Picture12.pngConfigure the Source Location as AWS CodeCommit as shown in below screenshot:

Picture13.pngConfigure the Build provider as AWS CodeBuild with the CodeBuild project created in Step 4 above as shown in below screenshot:

Picture14.pngWe just want to run tests and stop there for now. We will not deploy anything in this project so we will select No Deployment option in Deploy section as shown in below screenshot:

Picture15.pngFinally, we need to configure AWS Service role as shown in below screenshot:

Picture16.pngThis will take you to IAM to define the new role:

Picture17.pngBack in CodePipeline make sure the role is specified:

Picture18.png

Review the CodePipeline configuration and create the pipeline.

Picture19.png

You will see the Pipeline created success message. You can try invoking the newly created Pipeline by clicking the Release Change button:

Picture20

Once the Pipeline is executed you will see a both Source and Build stages in Green (unless there are any errors) as shown in below screenshot:

Picture21

After a successful run, you can go and check the S3 bucket to view the report.

Picture22.png

Newman generates a nicely formatted report as shown in below screenshot:

Picture23.png

You can also configure a Lambda function or SNS to send a notification along with the report.