Use Jenkins Like a Superhero

We’re all aware of Jenkins’ capabilities as a continuous integration tool and its significance in the DevOps space. But, do you know that in addition to automating and deploying the software builds, Jenkins can also be used in a wide range of software operations? For instance, some teams prefer Jenkins’ task scheduling over the standard Linux task scheduler, which can be cumbersome as it offers little help in monitoring or reporting of tasks. On the other hand, Jenkins provides a better environment with execution history and a lot of plugins that make things simple. Moreover, Jenkins supports the cron syntax for defining a schedule (@hourly or @daily).

However, now and then, we also come across instances where Jenkins’ task scheduling capabilities are used to solve unique challenges in a creative way. Douglas West a developer who is working Lululemon recently used Jenkins to book the first show tickets of the movie Avengers: EndGame.

Douglas found a problem with email notifications for movie ticket sales availability. Notifications frequently came hours later after tickets were available for purchase on the website. Expecting an unprecedented rush for the coveted tickets, and being an avid Avengers fan, he took things into his own hands.

“I realized I could solve this using Jenkins (or really, any task scheduling tool, even cron, but Jenkins ties it all together and has nice integrations with notification tools),” Douglas said. “I authored a freestyle job which ran once an hour. I did a baseline get of the ticket sales web page for my chosen theater for the opening day calendar entry for Avengers: EndGame. Initially, its content was mainly to the effect of “Ticket sales are not yet available” (along with a couple of k of supporting HTML). I dropped this base html file into the workspace of this job and authored a bash shell build step which performed a wget of the current same web page and did a diff against my saved base web page. If there were differences, then the job failed and upon failure sent me a personal slack message - complete with a hotlink to the ticket sales page in the message - for prompt purchasing.”

Douglas described how the website built up buzz and made small changes in the web page, as D-day came closer. These changes triggered false alerts, and he had to restart the process again by rebasing the saved HTML file. To improve his odds, Douglas tweaked the code to run the job every five minutes. Further, as a double-check, he made changes to receive alerts via SMS on his phone, in addition to those on Slack. Finally, when the tickets went on sale online, the code worked and sent instant notifications. Alas, Douglas missed the notifications due to the time-zone difference. Oops.

“They went live at 6 am East Coast time,” Douglas recalled. “Well, I live on the west coast, and that was 2 am my time. I did not wake up to see the messages (both from Slack and message+) until 7:30 am that morning west coast time.”

While Douglas wasn’t able to book the tickets precisely the way he wished, he was able to watch the movies at a nearby theater. Douglas suggests that anyone using Jenkins can replicate this application with a few lines of code, calling it “pretty basic.”

“I won’t post the code - it’s pretty basic,” Douglas noted. “One initial wget saved to a base state file previous to the job being scheduled, a wget to another file followed by a file diff command between the base and the just gotten file, and fail the job run if differences are found (remember NOT to clean the workspace - you don’t want to lose your base state file!). And then a post-build notification step upon job run failure. Easy peasy.”

Basic or not, the code solves a real-world problem in a very effective way. If you’ve used Jenkins for solving unique operational or day-to-day life challenges, please share your stories with us. You can contact me at dhwang@cloudbees.com.

If you want to find out more about using Jenkins and learning from your peers, come see us at DevOps World | Jenkins World 2019 in San Francisco. Register and join the fun!

Additional resources: