简体   繁体   English

如何使用Jenkins从已保存的AMI启动Amazon EC2 VM?

[英]How do I start an Amazon EC2 VM from a saved AMI using Jenkins?

I'm trying to create a Jenkins job to spin up a VM on Amazon EC2 based on an AMI that I currently have saved. 我正在尝试创建一个Jenkins作业,以基于当前已保存的AMI在Amazon EC2上启动VM。 I've done my searching and can't find an easy way to do this other than through Amazon's GUI. 我已经完成搜索,除了通过Amazon的GUI之外,找不到其他简便的方法。 This isn't very ideal as there are a lot of manual steps involved and it's time-consuming. 这不是很理想,因为涉及很多手动步骤,而且很耗时。

If anyone's had any luck doing this or could point me in the right direction that would be great. 如果有人这样做有运气,或者可以指出正确的方向,那就太好了。

Cheers, Darwin 干杯,达尔文

Unless I'm misunderstanding the question this should be possible using the cli, assuming you can install and configure the cli on your jenkins server you can just run the command as a shell script as part of the build. 除非我对这个问题有误解,否则使用cli应该可以实现这一点,假设您可以在jenkins服务器上安装和配置cli,则可以在构建过程中将命令作为shell脚本运行。

Create an instance with CLI. 使用CLI创建实例。

The command would be something along the lines of: 该命令将类似于以下内容:

[path to cli]/aws ec2 run-instances --image-id ami-xyz 

If your setup is too complicated for a single cli command, I would recommend creating a simple cloudformation template . 如果您的设置对于单个cli命令而言过于复杂,建议您创建一个简单的cloudformation模板

If you are unable to install the cli, you could use any number of sdk's eg java to make a simple application you could run with jenkins. 如果您无法安装cli,则可以使用任意数量的sdk(例如java)来制作可以使用jenkins运行的简单应用程序。

There is the Jenkins EC2 Plugin Jenkins EC2插件

Looking at the document it looks like you may be able to reuse your AMI. 查看该文档,看来您可以重用AMI。 If not, you can configure it with an init script 如果没有,您可以使用初始化脚本进行配置

Next, configure AMIs that you want to launch. 接下来,配置要启动的AMI。 For this, you need to find the AMI IDs for the OS of your choice. 为此,您需要找到所选操作系统的AMI ID。 ElasticFox is a good tool for doing that, but there are a number of other ways to do it. ElasticFox是执行此操作的好工具,但是还有许多其他方法可以执行此操作。 Jenkins can work with any Unix AMIs. Jenkins可以与任何Unix AMI一起使用。 If using an Ubuntu EC2 or UEC AMI you need to fill out the rootCommandPrefix and remoteAdmin fields under 'advanced'. 如果使用Ubuntu EC2或UEC AMI,则需要在“高级”下填写rootCommandPrefix和remoteAdmin字段。 Windows is currently unsupported. Windows目前不受支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM