2012-10-02 38 views
6

我需要創建在Amazon EC2上的Windows VM下運行的Jenkins代理雲。Jenkins亞馬遜EC2代理雲 - Windows奴隸

我的這個觀點很簡單的場景:

我有幾個預配置的AMI,每個虛擬機都有它匹配我的一個項目的特定環境。我有幾個項目需要經常構建以保持虛擬機運行。但是一些版本會每週運行一次,其他版本則會每週運行... Jenkins應該能夠在構建項目時自動啓動VM,並在構建完成時終止VM。我有幾個BCB項目和許多.NET項目,Windows作爲從VM OS是絕對必要的。

在安裝並配置Jenkins從站的情況下,準備預配置的AMI不是問題。但我不知道如何管理從主虛擬機(運行/終止它們)

我發現可用於運行和終止虛擬機的Amazon EC2插件。但它也試圖在那裏安裝和運行slave。不幸的是,Windows從站還不支持。 有沒有辦法使用預先配置的AMI或讓Amazon EC2插件在Windows VM上安裝代理?

我也嘗試過使用TeamCity - 它可以運行預配置的Windows AMI並在那裏生成項目(確切地說我的場景)。但我需要太多的虛擬機,我的老闆還沒有準備好支付許可證(3個免費許可證是不夠的)

是否可以使用Jenkins作爲我的場景?它有其他的選擇嗎?

+0

你最終選擇哪種解決方案? – Zac

+0

我們使用腳本雲插件[鏈接](https://wiki.jenkins-ci.org/display/JENKINS/Scripted+Cloud+plugin) –

回答

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()