2016-09-06 102 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