Dmi*_*iev 7 .net build-automation continuous-integration jenkins
我需要创建在Amazon EC2上的Windows VM下运行的Jenkins代理云.
我对此的看法很简单:
我几乎没有预配置AMI,每个VM都有特定的环境,可以匹配我的一个项目.我很少有经常构建的项目来保持VM运行.但是一些构建将每周运行,其他构建将运行... Jenkins应该能够在构建项目时自动启动VM并在构建完成时终止VM.我有几个BCB项目和许多.NET项目,Windows作为从属VM OS是绝对必要的.
准备安装和配置Jenkins从站的预配置AMI不是问题.但我不知道如何从master管理这些从属VM(运行/终止它们)
我找到了可用于运行和终止VM的Amazon EC2插件.但它也试图在那里安装和运行奴隶.不幸的是,Windows奴隶还不支持.有没有办法在Windows VM上使用预先配置的AMI或让Amazon EC2插件安装代理?
我也尝试使用TeamCity - 它可以运行预先配置的Windows AMI并在那里构建项目(完全是我的场景).但我需要太多的虚拟机,我的老板还没有准备好支付许可证(3个免费许可证还不够)
可以在我的场景中使用Jenkins吗?还有其他选择吗?
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()
Run Code Online (Sandbox Code Playgroud)