Skip to content

Commit e35d467

Browse files
author
droberts2013
committed
Add extra_vars map, job tags, credentials
1 parent 7e41302 commit e35d467

File tree

10 files changed

+135
-66
lines changed

10 files changed

+135
-66
lines changed

build.gradle

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
*/
77

88
plugins {
9-
id "com.github.hierynomus.license" version "0.11.0"
9+
id "com.github.hierynomus.license" version "0.16.1"
1010
}
1111

1212
defaultTasks 'build'
1313
apply plugin: 'java'
14-
apply plugin: 'idea'
15-
apply plugin: 'eclipse'
16-
apply plugin: 'maven'
1714

18-
version='1.0.0'
15+
version='1.1.1'
1916
sourceSets.main.resources.srcDirs = ["src"]
2017

2118
license {

gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Wed May 02 14:39:33 CEST 2018
2+
languageLevel=1.11
3+
xlPluginsPluginVersion=1.3.5
4+
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.11.jdk/Contents/Home

gradle/buildViaTravis.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# This script will build the project.
3+
4+
SWITCHES="--info --stacktrace"
5+
6+
GRADLE_VERSION=$(./gradlew -version | grep Gradle | cut -d ' ' -f 2)
7+
8+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
9+
echo -e "Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]"
10+
./gradlew clean build $SWITCHES
11+
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ]; then
12+
echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']'
13+
./gradlew -Prelease.travisci=true clean snapshot $SWITCHES
14+
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
15+
echo -e 'Build Branch for Release => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG']'
16+
case "$TRAVIS_TAG" in
17+
*-rc\.*)
18+
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true clean candidate $SWITCHES
19+
;;
20+
*)
21+
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true clean final $SWITCHES
22+
;;
23+
esac
24+
else
25+
echo -e 'WARN: Should not be here => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG'] Pull Request ['$TRAVIS_PULL_REQUEST']'
26+
./gradlew clean build $SWITCHES
27+
fi
28+
29+
EXIT=$?
30+
31+
rm -f "$HOME/.gradle/caches/modules-2/modules-2.lock"
32+
rm -rf "$HOME/.gradle/caches/$GRADLE_VERSION/plugin-resolution"
33+
34+
exit $EXIT

gradle/dependencies.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dependencyManagement {
2+
versions {
3+
docBaseStyleVersion="3.0.3"
4+
xlDeployVersion="9.0.0-alpha.78"
5+
licenseDatabaseVersion="1.2.45"
6+
xlPlatformVersion="2019.2.0-alpha.75"
7+
}
8+
}

gradle/wrapper/gradle-wrapper.jar

-3.5 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
99
#
10-
# https://www.apache.org/licenses/LICENSE-2.0
10+
# http://www.apache.org/licenses/LICENSE-2.0
1111
#
1212
# Unless required by applicable law or agreed to in writing, software
1313
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -82,7 +82,6 @@ esac
8282

8383
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
8484

85-
8685
# Determine the Java command to use to start the JVM.
8786
if [ -n "$JAVA_HOME" ] ; then
8887
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -126,11 +125,10 @@ if $darwin; then
126125
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127126
fi
128127

129-
# For Cygwin or MSYS, switch paths to Windows format before running java
130-
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
128+
# For Cygwin, switch paths to Windows format before running java
129+
if $cygwin ; then
131130
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132131
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133-
134132
JAVACMD=`cygpath --unix "$JAVACMD"`
135133

136134
# We build the pattern for arguments to be converted via cygpath
@@ -156,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
156154
else
157155
eval `echo args$i`="\"$arg\""
158156
fi
159-
i=`expr $i + 1`
157+
i=$((i+1))
160158
done
161159
case $i in
162-
0) set -- ;;
163-
1) set -- "$args0" ;;
164-
2) set -- "$args0" "$args1" ;;
165-
3) set -- "$args0" "$args1" "$args2" ;;
166-
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167-
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168-
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169-
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170-
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171-
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
160+
(0) set -- ;;
161+
(1) set -- "$args0" ;;
162+
(2) set -- "$args0" "$args1" ;;
163+
(3) set -- "$args0" "$args1" "$args2" ;;
164+
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165+
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166+
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167+
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168+
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169+
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172170
esac
173171
fi
174172

@@ -177,9 +175,14 @@ save () {
177175
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178176
echo " "
179177
}
180-
APP_ARGS=`save "$@"`
178+
APP_ARGS=$(save "$@")
181179

182180
# Collect all arguments for the java command, following the shell quoting and substitution rules
183181
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184182

183+
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
184+
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
185+
cd "$(dirname "$0")"
186+
fi
187+
185188
exec "$JAVACMD" "$@"

gradlew.bat

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@rem you may not use this file except in compliance with the License.
66
@rem You may obtain a copy of the License at
77
@rem
8-
@rem https://www.apache.org/licenses/LICENSE-2.0
8+
@rem http://www.apache.org/licenses/LICENSE-2.0
99
@rem
1010
@rem Unless required by applicable law or agreed to in writing, software
1111
@rem distributed under the License is distributed on an "AS IS" BASIS,
@@ -29,9 +29,6 @@ if "%DIRNAME%" == "" set DIRNAME=.
2929
set APP_BASE_NAME=%~n0
3030
set APP_HOME=%DIRNAME%
3131

32-
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
33-
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34-
3532
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
3633
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
3734

@@ -40,7 +37,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4037

4138
set JAVA_EXE=java.exe
4239
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
40+
if "%ERRORLEVEL%" == "0" goto init
4441

4542
echo.
4643
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -54,7 +51,7 @@ goto fail
5451
set JAVA_HOME=%JAVA_HOME:"=%
5552
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5653

57-
if exist "%JAVA_EXE%" goto execute
54+
if exist "%JAVA_EXE%" goto init
5855

5956
echo.
6057
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -64,14 +61,28 @@ echo location of your Java installation.
6461

6562
goto fail
6663

64+
:init
65+
@rem Get command-line arguments, handling Windows variants
66+
67+
if not "%OS%" == "Windows_NT" goto win9xME_args
68+
69+
:win9xME_args
70+
@rem Slurp the command line arguments.
71+
set CMD_LINE_ARGS=
72+
set _SKIP=2
73+
74+
:win9xME_args_slurp
75+
if "x%~1" == "x" goto execute
76+
77+
set CMD_LINE_ARGS=%*
78+
6779
:execute
6880
@rem Setup the command line
6981

7082
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7183

72-
7384
@rem Execute Gradle
74-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
85+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
7586

7687
:end
7788
@rem End local scope for the variables with windows NT shell

src/ansibletower/launchAndWait.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
import time
2727
import sys
2828

29+
def create_payload(extra_vars, jobTags, credentials):
30+
body = {}
31+
body['extra_vars'] = extra_vars
32+
body['job_tags'] = ",".join(jobTags)
33+
body['credentials'] = credentials
34+
body_as_string = json.dumps(body)
35+
print "Body returned from create_payload() is %s" % body_as_string
36+
return body_as_string
37+
2938
if not ansibletower:
3039
print("Ansible Tower Server must be provided")
3140
sys.exit(1)
@@ -40,26 +49,27 @@
4049

4150
if not isWorkflow:
4251
api_url = '/api/v2/job_templates/%s/launch/' % job_template_id
43-
body = { "extra_vars": extra_vars}
44-
response = request.post(api_url,body= json.dumps(body),contentType="application/json",headers=headers)
52+
# body = { "extra_vars": extra_vars}
53+
body_as_string = create_payload(extra_vars, jobTags, credentials)
54+
response = request.post(api_url,body=body_as_string,contentType="application/json",headers=headers)
4555
result = json.loads(response.response)
4656
# Check the response status code to make sure the request was not successful.
47-
57+
4858
if not response.isSuccessful():
4959
print("Failed to run the job template. Server return [%s], with content [%s]" % (response.status, response.response))
5060
sys.exit(1)
51-
61+
5262
job_id= result["id"]
53-
63+
5464
print("```")
5565
print(">>> Job template launched with job id " + str(job_id))
5666
print("```")
5767
print("\n")
58-
68+
5969
num_tries = 0
6070
api_url = '/api/v2/jobs/%s/' % job_id
6171

62-
72+
6373
if max_retries:
6474
while num_tries < int(max_retries):
6575
# Define the URL for the Ansible Tower API endpoint to launch a job.
@@ -75,12 +85,12 @@
7585
time.sleep(float(wait_interval))
7686
else:
7787
raise Exception("Failed !. Server return [%s], with content [%s]" % (response.status, response.response))
78-
88+
7989
if num_tries == int(max_retries):
8090
# maximum number of tries reached, handle the error
8191
raise Exception("Error: maximum number of tries reached")
8292
else:
83-
# task completed
93+
# task completed
8494
print("```")
8595
print(">>> Task completed after " + str(num_tries) + " tries with status "+ status)
8696
print("```")
@@ -93,7 +103,7 @@
93103
print("* [>>> Job %s Link](%s/#/jobs/%s) <<<" % (str(job_id), ansibletower['url'], str(job_id)))
94104
print("\n")
95105
result= job_output
96-
106+
97107
else:
98108
while True:
99109
# Define the URL for the Ansible Tower API endpoint to launch a job.
@@ -122,22 +132,23 @@
122132
result= job_output
123133
else:
124134
api_url = '/api/v2/workflow_job_templates/%s/launch/' % job_template_id
125-
body = { "extra_vars": extra_vars}
126-
response = request.post(api_url,body= json.dumps(body),contentType="application/json",headers=headers)
135+
# body = { "extra_vars": extra_vars}
136+
body_as_string = create_payload(extra_vars, jobTags, credentials)
137+
response = request.post(api_url,body=body_as_string,contentType="application/json",headers=headers)
127138
result = json.loads(response.response)
128139
# Check the response status code to make sure the request was not successful.
129-
140+
130141
if not response.isSuccessful():
131142
print("Failed to run the workflow job template. Server return [%s], with content [%s]" % (response.status, response.response))
132143
sys.exit(1)
133-
144+
134145
job_id= result["id"]
135-
146+
136147
print("```")
137148
print(">>> Workflow job template launched with job id " + str(job_id))
138149
print("```")
139150
print("\n")
140-
151+
141152
num_tries = 0
142153
api_url = '/api/v2/workflow_jobs//%s/' % job_id
143154
if max_retries:
@@ -155,12 +166,12 @@
155166
time.sleep(float(wait_interval))
156167
else:
157168
raise Exception("Failed !. Server return [%s], with content [%s]" % (response.status, response.response))
158-
169+
159170
if num_tries == int(max_retries):
160171
# maximum number of tries reached, handle the error
161172
raise Exception("Error: maximum number of tries reached")
162173
else:
163-
# task completed
174+
# task completed
164175
print("```")
165176
print(">>> Task completed after " + str(num_tries) + " tries with status "+ status)
166177
print("```")
@@ -198,9 +209,7 @@
198209
print("\n") # end markdown code block
199210
print("* [>>> Job %s Link](%s/#/jobs/workflow/%s/output) <<<" % (str(job_id), ansibletower['url'], str(job_id)))
200211
print("\n")
201-
result= job_output
212+
result= job_output
202213

203214
if stopOnFailure and not status == 'successful':
204215
raise Exception("Job status is "+ status)
205-
206-

0 commit comments

Comments
 (0)