Skip to content

Commit

Permalink
Omit empty body elements, fail task on failed job
Browse files Browse the repository at this point in the history
  • Loading branch information
droberts2013 committed Jun 23, 2023
1 parent e494501 commit b36d4b5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
defaultTasks 'build'
apply plugin: 'java'

version='1.1.7'
version='1.1.8'
sourceSets.main.resources.srcDirs = ["src"]

license {
Expand Down
9 changes: 6 additions & 3 deletions src/ansibletower/launchAndWait.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@

def create_payload(extra_vars, jobTags, credentials):
body = {}
body['extra_vars'] = extra_vars
body['job_tags'] = ",".join(jobTags)
body['credentials'] = credentials
if extra_vars:
body['extra_vars'] = extra_vars
if jobTags:
body['job_tags'] = ",".join(jobTags)
if credentials:
body['credentials'] = credentials
body_as_string = json.dumps(body)
print "Body returned from create_payload() is %s" % body_as_string
return body_as_string
Expand Down
7 changes: 5 additions & 2 deletions src/ansibletower/launchAndWait.wait_for_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def formatted_print(message):
result = json.loads(response.response)
status=result['status']
task.setStatusLine("Job id %s %s" % (job_id, status))
formatted_print(">>> Task status after " + str(num_tries) + " tries is "+ status)
formatted_print(">>> Job status after " + str(num_tries) + " tries is "+ status)
print(link_message % (str(job_id), ansibletower['url'], str(job_id)))
print("\n")
if status in ["running","pending","waiting"]:
Expand All @@ -65,6 +65,9 @@ def formatted_print(message):
job_output=request.get(api_url+'stdout/', contentType='text/plain',headers=headers).response
formatted_print(job_output)
result = job_output
if status in ["failed"]:
formatted_print(">>> Job failed after " + str(num_tries) + " tries")
raise Exception("Error: job failed")
else:
formatted_print(">>> Task failed after " + str(num_tries) + " tries. Job status was not retrieved.")
raise Exception("Failed: Server return [%s], with content [%s]" % (response.status, response.response))
raise Exception("Error: server returned [%s], with content [%s]" % (response.status, response.response))
2 changes: 1 addition & 1 deletion src/plugin-version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
#SOFTWARE.

plugin=xlr-ansible-automation-controller-plugin
version=1.1.7
version=1.1.8

0 comments on commit b36d4b5

Please sign in to comment.