Deployment By Hardware

In this post I detail how to use IoT hardware to deploy software.

Here is what is needed to setup an IoT deployment

  • A Jenkins Server with Internet connectivity and a job to build and deploy software.
  • A Gmail or Office 365 email account (Jenkins email account).
  • A IFTTT account
  • IoT Hardware, This can be any of the following:
    • Tablet (iOS or Android).
    • Smartphone (iOS or Android).
    • Android Wear
    • Amazon Echo
    • IoT button, I highly recommend Particle's Internet Button since it's hackable and has an led display to indicate when deployment is be done.

Jenkins Settings


On the Jenkins server, install the poll-mailbox-trigger-plugin. Once the plugin add the poll mailbox trigger using the Jenkins email account and ensure in the advance options add the line "SubjectContains=" followed by the subject of your email you want Jenkins to trigger a build (ie. SubjectContains=BuildAndDeploy). Save and test your changes (you should be able to trigger the build with an email).

IFTTT Settings


Now depending on what IoT hardware you will be setting up an IFTTT action to send an email to the Jenkins Email account.

Make sure you have the gmail or Office 365 mail channel connected to your IFTTT account.

All IoT will be using an email THEN option (either the Gmail or Office 365 Mail Channel). This option will send an email to the Jenkins email with the subject specified on the poll mail box trigger on the Jenkins Server

For Smartphones or Tablets

  • Install the DO Button app and the IF app (Google Play or App Store).
  • On your mobile device open the DO Button app and create a new recipe. Look for the Gmail or Office 365 Mail channel and click create new recipe.

For Android Wear

  • Install the IF app from above on your phone and then create a recipe.
  • Select Android Wear for the IF option and Gmail or the Office 365 Mail channel for the THEN option.

For Amazon Echo

  • Connect the Amazon Alexa Channel to your IFTTT account.
  • Create a new recipe with the Amazon Alexa Channel as the IF trigger when you say a specific phrase and Gmail or the Office 365 Mail channel for the THEN option.

For Particle Internet Button

To set the Particle Internet button add the following to a button press event in the button's ino file:
Particle.publish("DEPLOY");
Once that is done do the following:

  • Connect the Particle Channel to your IFTTT account.
  • Create a new recipe with the particle channel as the IF trigger using the new event published with the named "DEPLOY" and Gmail or the Office 365 Mail channel for the THEN option.


The Particle Internet button is one of the better choices for Deployment by Hardware because it allows you also see feedback once a Jenkins. For this you have to do the following:
  • Setup the button with a cloud monitoring function by adding the following to button's ino file:
int monitorSite(String command);
void setup() {
    b.begin();
    Particle.function("monitor", monitorSite);
}
int monitorSite(String command) {
    else if (command == "Deployed Dev") {
        for (int i = 0; i < 12; i++) {
            b.ledOn(i, 0, 255, 0);
        }
        return 1;
    }
    else if (command == "Deploying Dev") {
        for (int i = 0; i < 12; i++) {
            b.ledOn(i, 0, 0, 255);
        }
        return 1;
    }
    else if (command == "Failed Deploying Dev") {
        for (int i = 0; i < 12; i++) {
            b.ledOn(i, 255, 0, 0);
        }
        return 1;
    } 
  • Make a curl script that Jenkins will use that will activate the button's leds.
#!/bin/bash
curl -s https://api.particle.io/v1/devices/[BUTTON ID]/monitor \
     -d access_token=[TOKEN] \
     -d "args=$1"
*** The BUTTON ID can be found in your devices in the console of particle.io and the TOKEN can be found on the settings tab of the Web IDE.
  •  Add curl script to the Jenkins job in the right places and you should see the button light up as the job works.


Final Remarks


The Deployment by Hardware concept can be used for more than just deploying software. I've used it to monitor a deployed website, turn on and off maintenance pages, restore my development environment, and backing up of data from a deployed website.

Comments

Popular posts from this blog

Upgrading to Grails 3.2.0 from Grails 2.3.7 with Spring Security and Deployment to Tomcat7