Build solution for Jenkins with Amazon EC2 – How to keep state between builds

amazon ec2amazon-ebs

I'm trying to move my build environment to EC2 using Jenkins. I have a lot of source to check out each time, so I want to preserve the source persistently between builds.

This would be easy if Jenkins stopped/started the EC2 instances when it needed them (as I could just associate the AMI with a root EBS volume). But Jenkins terminates the instances when not being used.

I have tried making a separate EBS volume and attaching it to the EC2 instance using the startup commands with Jenkins and the problem there is it's possible for the EBS volume and EC2 instance to be in different availability zones. And Jenkins cannot control the availability zone when starting the instance.

So is there a way to keep the state between builds using the Jenkins/EC2 interface. Snapshots perhaps?

See this non-question from me for a bit more context.

Best Answer

I took a look at the source code of Jenkins and that's a reasonable fix to it. It won't take much hacking to add the option of selecting which availability zone in a region one wants or to change termination to a simple stop. I think that's the best approach here.

If sufficiently motivated, I might post a patch. Source code is at https://github.com/jenkinsci/ec2-plugin/ if you're handy with Java.