Jenkins Amazon EC2代理云 - Windows从机

7
我需要创建在Amazon EC2上运行的Windows虚拟机(VM)下的Jenkins代理云。
我的想法是一个简单的场景:我有一些预配置的AMIs,每个VM都有特定的环境,与我的项目之一相匹配。我有几个项目需要构建,以保持VM运行。但有些构建将每周运行,其他的每月运行…… Jenkins应该能够在需要构建项目时自动启动VM,并在构建完成后终止VM。我有几个BCB项目和许多.NET项目,Windows作为从属VM操作系统是绝对必要的。
准备预配置的AMI并安装和配置Jenkins从属不是问题。但我不知道如何从主服务器管理这样的从属VM(运行/终止它们)。
我发现Amazon EC2插件可以用于运行和终止VMs。但它也试图在那里安装和运行从属。不幸的是,Windows从属尚未得到支持。 有没有办法使用预配置的AMI或让Amazon EC2插件在Windows VM上安装代理?
我也尝试过使用TeamCity - 它可以运行预配置的Windows AMI并在那里构建项目(完全符合我的情况)。但我需要太多的VM,而我的老板还没有准备好支付许可证费用(3个免费许可证还不够)。
是否可能在我的情况下使用Jenkins?还有其他的替代方案吗?

你最终采用了什么解决方案? - Zac
我们使用Scripted Cloud插件链接 - Dmitry Vasiliev
1个回答

0

boto.ec2 可以完美地用于随时启动/停止/终止实例。

我使用一个脚本来完成这个操作。这里是一部分代码,我可以分享给你。但有些部分我无法分享,请谅解。

#!/usr/bin/python
import boto.ec2
import sys
import time

# specify AWS keys
auth = {"aws_access_key_id": "YOUR_KEY", "aws_secret_access_key": "YOUR_SECRET_KEY"}

def main():
    # read arguments from the command line and
    # check whether at least two elements were entered
    if len(sys.argv) < 2:
        print "Usage: python aws.py {start|stop}\n"
        sys.exit(0)
    else:
        action = sys.argv[1]

    if action == "start":
        startInstance()
    elif action == "stop":
        stopInstance()
    else:
        print "Usage: python aws.py {start|stop}\n"

def startInstance():
    print "Starting the instance..."

    # change "eu-west-1" region if different
    try:
        ec2 = boto.ec2.connect_to_region("eu-west-1", **auth)

    except Exception, e1:
        error1 = "Error1: %s" % str(e1)
        print(error1)
        sys.exit(0)

    # change instance ID appropriately
    try:
        instances = ec2.start_instances(instance_ids="ID_INSTANCE TO START")

        instances[0].update()
        while instances[0].state != "running":
            print instances[0].state
            time.sleep(5)
            instances[0].update()

#this part manage the association of Elastic IP
        ec2.associate_address("ID_INSTANCE","ELASTIC IP")


    except Exception, e2:
        error2 = "Error2: %s" % str(e2)
        print(error2)
        sys.exit(0)

def stopInstance():
    print "Stopping the instance..."

    try:
        ec2 = boto.ec2.connect_to_region("eu-west-1", **auth)

    except Exception, e1:
        error1 = "Error1: %s" % str(e1)
        print(error1)
        sys.exit(0)

    try:
        ec2.stop_instances(instance_ids="INSTANCE_ID")

        instances[0].update()
        while instances[0].state != "stopped":
            print instances[0], instances[0].state
            time.sleep(5)
            instance.update()

        print "Instance stopped : "

    except Exception, e2:
        error2 = "Error2: %s" % str(e2)
        print(error2)
        sys.exit(0)

if __name__ == '__main__':
    main()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接