-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_release_orchestration.py
More file actions
47 lines (40 loc) · 1.76 KB
/
Copy path03_release_orchestration.py
File metadata and controls
47 lines (40 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Example 03 - Provisioning a release through the API objects
#
# Create template -> add phase -> add task -> start release, using the reserved API
# objects (templateApi / phaseApi / taskApi / releaseApi). The java.util.Date schedule
# is auto-converted to datetime, so this migrates with no markers left.
# Java classes, imported by their XL Release package names.
from com.xebialabs.xlrelease.domain import Release
from com.xebialabs.xlrelease.domain.status import ReleaseStatus
from com.xebialabs.xlrelease.api.v1.forms import CreateRelease
from java.util import Date
# Seed a couple of sample inputs into the reserved releaseVariables map.
releaseVariables["appName"] = "petclinic"
releaseVariables["targetEnv"] = "production"
# Read the inputs back from the map.
appName = releaseVariables["appName"]
targetEnv = releaseVariables["targetEnv"]
# 1. Create a template (status must be TEMPLATE, with a scheduled start and due date).
scheduledStart = Date()
dueDate = Date(scheduledStart.getTime() + 7 * 24 * 60 * 60 * 1000)
template = templateApi.createTemplate(
Release(
title="Deploy %s" % appName,
status=ReleaseStatus.TEMPLATE,
scheduledStartDate=scheduledStart,
dueDate=dueDate,
),
None,
)
print "Created template", template.id
# 2. Add a phase to the template.
phase = phaseApi.addPhase(template.id, phaseApi.newPhase("Deploy to %s" % targetEnv))
print "Added phase", phase.title
# 3. Add a task to that phase.
task = taskApi.addTask(phase.id, taskApi.newTask("xlrelease.Task"))
print "Added task", task.id
# 4. Create a release from the template and start it.
release = templateApi.create(
template.id, CreateRelease(releaseTitle="Deploy %s to %s" % (appName, targetEnv)))
releaseApi.start(release.id)
print "Started release", release.id