Jenkins git triggered build not blocking
Question: I am running a build on commit to `origin/master` on my jenkins server that is
deploying resources to Amazon AWS. I am using the Execute Shell section to run
a python script that handles all unit testing/linting/validation/deployment
and everything blocks fine until it gets to the deployment (`deploy.deploy()`)
where it returns a success right after kickoff, but doesn't complete
deploying. How can I make this block?

For reference here is my config:

**Execute Shell (Jenkins)** :

    
    
    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"
    


Answer: You can use api calls to aws to retrieve the status and wait until it become
'some status'.

The below example is psuedo-code to illustrate the idea:

    
    
    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
    

