Intro: Jenkins Job Traffic Lights
In software engineering, continuous integrationis the practice of merging all developer working copies to a shared mainline several times a day. Some of the best practices to achieve that are:
- everyone commits to the baseline every day,
- automate the build,
- everyone can see the results of the latest builds.
- ...and many others.
To fulfill just these 3 points above, it is important to be notified about build status as fast as possible.
This project helps to achieve that by creating a mini, personal traffic lights which indicates current build status. I've built 2 sets of traffic lights which are integrated to Jenkins automation server which is pulled by NodeMCU periodically via WiFi.
Step 1: Materials and Tools
Materials I used:
- NodeMCU (I used v3) (BangGood.com)
- Male to Female breadboard jumper cables, (BangGood.com)
- 2 sets of LEDs: red, yellow, green (BangGood.com)
- 2 sets of 3 resistors (450Ω, 500Ω, 22Ω)
- 2 thin but long prototype PCB boards (BangGood.com)
- microUSB cable as a power supply
- Some box (I used one for electric high voltage components. I found many different shapes and cheap in my local DIY retailer store)
- 2 pens or 2 thick pipes 0.5-1cm internal diameter; and/or 2 thick drink straws
- Sharp knife (e.g. utility knife for cutting carpet)
- Rotary tool
- Hot glue gun
- Soldering station
- Pliers, diagonal pliers/side cutters
- Piece of thick paper
- Double-sided adhesive tape
Step 2: Traffic Lights
To build traffic lights, we use prototyping board 20x80mm. Solder LEDs so they are positioned in a line. I've used these resistor values:
- red: 510Ω
- yellow: 470Ω
- green: 22Ω
Values are much higher than recommended (20mA max current per LED), but experimenting with different values, the light is not too bright and also all 3 have similar intensity. Please note that voltage is 3.3V for NodeMCU.
Wiring is straight forward, just connect (solder) cathode of each LED with resistor and then solder to male ending of jumper cable. On one side of the board I wanted only LED elements without any other "popping up" parts like resistor legs, wires and so on. That's why I've used a "technique" which is a kind of SMD using PCB components.
We leave it like this for now; the lights cover will be done later.
Step 3: Box - Main
We need to embed our NodeMCU to the bottom of the box. The box needs a hole for microUSB port so we can power up the main unit. I measured raughly the hole position and I just drilled it.
Then I attached the plastic spacers using screws to nodemcu. I put some glue in each corner of the box and I put the whole construction onto it. After it cooled down, I unscrewed NodeMCU and put some additional hot glue around the spacers which I was sure were positioned perfectly for NodeMCU. Thanx to this, nothing is wobbling inside the box and we can easily attach the microUSB port without moving stuff inside.
Step 4: Box - Lid
First I tried to use a drink straws as a pole for my traffic lights but after some testing, I found out that the plastic is too thin and when I wanted to use a hot glue to attach it, it just got very soft and even changed its shape. So I decided to use something harder - pens. I've chosen some cheap transparent pens, which I cut off in desired length and put 4 cables (1 at a time) from traffic lights through the pipe.
I drilled holes in a middle line of the lid according to the pen's diameter. Then I embedded pens inside holes and I hotglued them on the bottom side of the lid trying to keep the poles straight.
I put also some hot glue on top of the pole to attach the traffic lights boards to the poles.
Step 5: Assembling
I connected wires to the NodeMCU (pinout):
Left traffic light:
- red to D2 (GPIO4)
- yellow to D3 (GPIO0)
- green to D4 (GPIO2)
- ground to GND (I just chose one of GND pin of NodeMCU)
RIght traffic light:
- red to D5 (GPIO14)
- yellow to D6 (GPIO12)
- green to D7 (GPIO13)
- ground to GND (Ijust chose one of GND pin of NodeMCU)
...and I closed the lid. The wires I chose were quite long so I had a little problems with putting them all inside the small box, but somehow I managed to do it.
Step 6: Lights' Cover
I couldn't find any ready solutions as a lights' covers - some kind of boxes from candies or so. So I decided to build them by hand just by cutting a box from a paper.
The size of the box I chose was: 20mm x 15mm x 85mm.
I cut the holes so that I cut a kind of "stars" in proper places where the LEDs were positioned. I glued them using double sided adhesive tape.
To cover the transparent poles, You can use some permanent marker, nontransparent scotch tape,... I used black drink straws which I cut through from end to end. Then I covered the poles.
I was more than happy of final result.
Step 7: Software
There are many approaches to indicate the current build state. I implemented such a behavior:
Red or green light lights up when the build is failing or passing accordingly. Yellow light blinks every time there is made an HTTP call and is continously switched on when a plan is currently building.
You can easily change the implementation according to Your needs - try to experiment and check what fits You and/or Your team.
You need to setup the code before uploading it to Your NodeMCU. You need to set max 2 WiFis.
Also You need to set Your user token. To get API token, click on Your user name on top-right in Jenkins, then Configuration. You can find a button "Show API token". To build the Basic authentication value, create a string using the pattern:
and then encode it using Base64. E.g. for above fake string, You should get Base64 value:
You have to also set Your Jenkins host, port and 2 jobs' paths.
After this setup and uploading the sketch - You are ready to use Your traffic lights.
Code is also available on GitHub.
Step 8: Last Words
To power on the device, just connect the device to any USB socket. It uses WiFi conection to access Internet so any working USB socket is OK - either computer port or charger. After a boot up and connecting to WiFi, Your traffic lights will start showing the current build status.
I find this traffic lights very usefull. They are standing next to my monitors in office and whenever red light lights up - I notice it immediately. I don't need to waste time to check the build statuses directly on Jenkins.
One improvement could be done by using some traffic lights toy instead of building one by myself from scratch (junk?).
I hope You find some inspiration to build Your own Jenkins integrated traffic lights.