All posts

Execute MyGarage builds on EC2 Instance

After being able run my app on Ubuntu as a service, I wanted to move my build process to cloud as well. So, first, I installed Jenkins on the AWS EC2 Machine.

Now when I run a job in jenkins, it should use one of the EC2 instance as its slave and complete build. For this I used EC2 Plugin which allows to setup any EC2 instance as a jenkins slave.

There are several articles on how to configure this plugin, However, I followed this video where its clearly explained which configurations are needed to setup EC2 instance as jenkins slave.

The advantage with this approach is that only when a jenkins job is started, a new EC2 instance of the alerady defined configuration is spawned. This is treated as jenkins slave and job is completed. We do have the option to set Idle time ex: 5 or 10 mins. So if there is no other job requesting any EC2 instance for job execution the instance is automatically terminated.

For most of the simple jobs t2 micro is enough.

A few important observations when i did this experiment:

  1. When the EC2 instance is created it took several minutes to connect via ssh. sometimes delay was due to job not being able to read from the EC2 console. I had to try setting different values to Host Key Verification Strategy field in the plugin. ‘check-new-soft’ or ‘accept-new’ values worked for me. More details can be found in the plugin page under Security section here
Screenshot 1 from "Execute MyGarage builds on EC2 Instance"

2. Another challenge was that my EC2 instances were getting created and terminated within a minute without executing job. I spent good amount of time to figure out the cause. Later I noticed one difference, I was using Ubuntu as master to spawn slaves. When I changed the AMI ID to Amazon Linux it worked flawlessly. One reason is that Amazon Linux installs Java if its not installed by itself. I am still trying to make it work with Ubuntu

Screenshot 2 from "Execute MyGarage builds on EC2 Instance"

So, now whenever I trigger a job in my jenkins my build is running on a On Demand EC2 instance.

Next, i am working with Spot Instances, will list my observations in next blog

First published on my old blog, Write Code. Be Agile. Go DevOps.