2012-10-02 3 views
6

Amazon EC2의 Windows VM에서 실행되는 Jenkins 에이전트 클라우드를 만들어야합니다.Jenkins Amazon EC2 에이전트 클라우드 - Windows 슬레이브

내가 몇 AMI를이 VM의 각 내 프로젝트 중 하나와 일치 특정 환경을 사전 구성이이의

내보기는 간단한 시나리오입니다. VM을 계속 실행하기에 충분히 자주 빌드 할 프로젝트가 거의 없습니다. 그러나 일부 빌드는 매주 실행되고 다른 빌드는 mounthly로 실행됩니다. Jenkins는 프로젝트를 빌드해야 할 때 자동으로 VM을 시작하고 빌드가 완료되면 VM을 종료 할 수 있어야합니다. 몇 가지 BCB 프로젝트와 많은 .NET 프로젝트가 있습니다. Windows는 슬레이브 VM OS로서 절대적으로 필요합니다.

Jenkins 슬레이브가 설치되고 구성된 사전 구성된 AMI를 준비하는 것은 문제가되지 않습니다. 하지만 마스터에서 이러한 종속 VM을 관리하는 방법을 모릅니다. (실행/종료)

VM을 실행하고 종료하는 데 사용할 수있는 Amazon EC2 플러그인을 찾았습니다. 그러나 또한 슬레이브를 설치하고 실행하려고 시도합니다. 불행히도, windows 노예는 아직 지원되지 않습니다. 미리 구성된 AMI를 사용하거나 Windows VM에 Amazon EC2 플러그인 설치 에이전트를 사용하는 방법이 있습니까?

TeamCity도 사용하려고했습니다. 사전 구성된 Windows AMI를 실행하고 거기에 프로젝트를 빌드 할 수 있습니다 (정확한 시나리오). 하지만 너무 많은 VM이 필요하고 사장이 라이센스 비용을 지불 할 준비가되지 않았습니다. (무료 라이센스 3 개로 충분하지 않습니다.)

시나리오에 젠킨스를 사용할 수 있습니까? 다른 대안이 있습니까?

+0

어떤 솔루션을 사용 했습니까? – Zac

+0

Scripted Cloud Plugin [link] (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()