Sometimes you need to keep an eye on those Jenkins build jobs 🤓🚦.

Intro

According to the Jenkins documentation there are the following build states:

  • ABORTED
  • FAILURE
  • NOT_BUILT
  • SUCCESS
  • UNSTABLE

Which are visualized with a colored circle: ,, …, which we can map to states of the traffic light (see video above).

See my previous post if you need to build a tiny traffic light.

Code

This variant will rely on being plugged into the server or your local machine, and a script that will grab the status from jenkins and publish the result messages to the traffic light via the serial interface.

Unfortunately I lost the code for the script that does this, but I still have the Arduino code below that receives and maps the serial messages to the traffic light:

Make sure you have the FastLED library installed. In the menu you can select
Sketch -> Include Libraries -> Manage Libraries -> Search for “FastLED” and install.

#include "FastLED.h"
#define NUM_LEDS 5
#define DATA_PIN D5
#define TOP 0
#define MID 2
#define BOT 4
#define BRIGHTNESS 128
CRGB leds[NUM_LEDS];

void allOff() {
  setLed(0, 0, 0, 0);
  setLed(1, 0, 0, 0);
  setLed(2, 0, 0, 0);
  setLed(3, 0, 0, 0);
  setLed(4, 0, 0, 0);
}
void setLed(uint8_t i, uint8_t r, uint8_t g, uint8_t b) {
  leds[i] = CRGB(r, g, b);
}

void setup() {
  Serial.begin(9600);
  Serial.println("starting");

  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  allOff();
  setLed(MID, 0, 0, BRIGHTNESS);
  FastLED.show();
  delay(1000);
  allOff();
}

String input;

void loop() {
  if (Serial.available() > 0) {
    input = Serial.readString();
  }

  if (input == "SUCCESS") {
    allOff();
    setLed(BOT, 0, BRIGHTNESS, 0);
  } else if (input == "UNSTABLE") {
    allOff();
    setLed(MID, BRIGHTNESS, BRIGHTNESS, 0);
    FastLED.show();

  } else if (input == "FAILURE") {
    allOff();
    setLed(TOP, BRIGHTNESS, 0, 0);
    FastLED.show();
    
  }
  else if (input == "BUILDING") {
    allOff();
    setLed(MID, 0, 0, BRIGHTNESS);
    FastLED.show();

    delay(500);

    setLed(MID, 0, 0, 0);
    FastLED.show();

    delay(500);
    
  } else {
    allOff();
    setLed(MID, BRIGHTNESS, BRIGHTNESS, BRIGHTNESS);
    FastLED.show();

    delay(500);

    setLed(MID, 0, 0, 0);
    FastLED.show();

    delay(500);
  }


  FastLED.show();
  delay(50);
}