Jenkins git triggered build not blocking
<p>I am running a build on commit to <code>origin/master</code> 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 (<code>deploy.deploy()</code>) where it returns a success right after kickoff, but doesn't complete deploying. How can I make this block?</p>

<p>For reference here is my config:</p>

<p><strong>Execute Shell (Jenkins)</strong>:</p>

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

<p><strong>kickoff.py</strong></p>

<pre><code>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()
</code></pre>

<p><strong>deploy.py</strong></p>

<pre><code>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"
</code></pre>

<p>You can use api calls to aws to retrieve the status and wait until it become 'some status'.</p>

<p>The below example is psuedo-code to illustrate the idea:</p>

<pre><code>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
</code></pre>

python amazon-web-services jenkins