2016-09-06 98 views
2

我正在将资源部署到Amazon AWS的jenkins服务器上运行构建,提交到origin/master。我正在使用Execute Shell部分来运行一个处理所有单元测试/ linting/validation/deployment的python脚本,并且一切正常,直到它开始部署(deploy.deploy()),它在启动后立即返回成功,但没有完成部署。我怎样才能使这个块?Jenkins git触发构建不阻止

仅供参考,这里是我的配置:

执行shell(詹金斯)

export DEPLOY_REGION=us-west-2 
. build-tools/get_aws_credentials.sh 
python build-tools/kickoff.py 

kickoff.py

if __name__ == "__main__": 
    build_tools_dir="{}".format("/".join(os.path.abspath(__file__).split("/")[0:-1])) 
    sys.path.append(build_tools_dir) 
    base_dir = "/".join(build_tools_dir.split("/")[0:-1]) 
    test_begin = __import__("test_begin") 
    test_all_templates = __import__("test_all_templates") 
    deploy = __import__("deploy") 
    git_plugin = __import__("git_plugin") 
    retval = test_begin.entrypoint("{}/platform/backend".format(base_dir)) 
    if (retval == "SUCCESS"): 
     retval = test_all_templates.entrypoint("{}/platform/backend".format(base_dir)) 
     if (retval == "SUCCESS"): 
      deploy.deploy() 

deploy.py

def deploy(): 
    print(". {}/platform/backend/nu.sh --name jenkinsdeploy --stage dev --keyname greig --debug".format("/".join(os.path.abspath(__file__).split("/")[0:-2]))) 
    returnedcode = subprocess.call("sh {}/platform/backend/nu.sh --name jenkinsdeploy --stage dev --keyname colin_greig --debug".format("/".join(os.path.abspath(__file__).split("/")[0:-2])), shell=True) 
    if returnedcode == 0: 
     return "DEPLOY SUCCESS" 
    return "DEPLOY FAILURE" 
+0

加入一个API调用,“获取状态”为1分钟睡在while循环中,并打破循环,只有当“成功”收到 – chenchuk

+0

你也可以使用Python 3的'await'语义。 – boardrider

回答

0

您可以使用api调用aws来检索状态并等待,直到它变成'某种状态'。

下面的例子是伪代码来说明这个想法:

import time 
import boto3 
ec2 = boto3.resource('ec2') 

while True: 
    response = ec2.describe_instance_status(.....) 
    if response == 'some status': 
     break 
    time.sleep(60) 

# continue execution