Skip to content

Commit

Permalink
Merge pull request #13 from vlussenburg/master
Browse files Browse the repository at this point in the history
first stage: adding dependency add feature
  • Loading branch information
jdewinne committed Feb 18, 2016
2 parents 229fdfd + 60b3d23 commit f23d5c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Any XL Release version before 4.8.x should use version 1.6.5 or lower of the plu
* `releaseDescription`: Description of the subrelease (`string`)
* `variables`: Comma-separated key-value pairs for the values of variables required by the subrelease, e.g. var1=value1,var2=value2 (`string`)
* `asynch`: If [false], the task will wait for the subrelease to finish
* `gateTaskTitle`: Title of the gate task in this release that should wait for the subrelease to complete. Skipped if not specified (blank).

+ Create Template
* `templateName`: Name of the template to create (`string`)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/synthetic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<property name="releaseDescription" category="input" label="Release Description" required="false" size="large" description="Description of the subrelease."/>
<property name="variables" category="input" required="false" description="Comma-separated key-value pairs for the values of variables required by the subrelease, e.g. var1=value1,var2=value2"/>
<property name="asynch" category="input" required="false" kind="boolean" default="false" description="If [false], the task will wait for the subrelease to finish."/>
<property name="gateTaskTitle" category="input" required="false" kind="string" description="Title of the gate task in this release that should wait for the subrelease to complete. Skipped if not specified (blank)."/>

<property name="status" category="output" />
</type>
Expand Down
17 changes: 16 additions & 1 deletion src/main/resources/xlr/CreateAndStartSubRelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

from xlr.XLReleaseClientUtil import XLReleaseClientUtil

def find_planned_gate_task(tasks):
for task in tasks:
if task["status"] == "PLANNED":
return task

def process_variables(variables, updatable_variables):
var_map = {}
if variables is not None:
Expand Down Expand Up @@ -42,7 +47,7 @@ def process_variables(variables, updatable_variables):
# Start Release
xlr_client.start_release(release_id)

# Wait for subrelease to be finished (only if asynch is true)
# Wait for subrelease to be finished (only if asynch is false)
while not asynch:
status = xlr_client.get_release_status(release_id)
if status == "COMPLETED":
Expand All @@ -53,3 +58,13 @@ def process_variables(variables, updatable_variables):
sys.exit(1)
time.sleep(5)

if gateTaskTitle:
tasks = taskApi.searchTasksByTitle(gateTaskTitle, None, getCurrentRelease().id)
task = find_planned_gate_task(tasks)

if task is None:
print "Couldn't find a planned gate task with title %s in current release." % gateTaskTitle
sys.exit(1)

xlr_client.add_dependency(release_id, task.id)

18 changes: 18 additions & 0 deletions src/main/resources/xlr/XLReleaseClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,21 @@ def add_link(self, containerId, sourceTaskId, targetTaskId):
print "Failed to task link\n"
print xlr_response.errorDump()
sys.exit(1)

def add_dependency(self, dependencyReleaseId, gateTaskId):
# the internal api uses a rel-phase-task format instead of Applications/Rel/Phase/Task
# is there a cleaner way to do this??
# TODO move to public API once it is possible using the public API
internal_format_task_id = gateTaskId.replace('Applications/', '').replace('/', '-')

xlr_api_url = '/gates/%s/dependencies' % internal_format_task_id
content = { "target": { "releaseId" : dependencyReleaseId } }
xlr_response = self.httpRequest.post(xlr_api_url, json.dumps(content), contentType='application/json')

if xlr_response.isSuccessful():
print "Dependency added to Gate task\n"
else:
print "Failed to add dependency\n"
print xlr_response.errorDump()
sys.exit(1)

0 comments on commit f23d5c4

Please sign in to comment.