How to Start One Release From Another With XL Release
Join the DZone community and get the full member experience.
Join For FreeXL Release is a great tool to orchestrate releases. Sometimes we might want XL Release to orchestrate which releases we start. If this sounds kind of recursive, let’s examine a use case that was brought to me recently. The customer had a couple of release templates that might get started as part of their general release. Specifically, they talked about a release for their distributed systems and another release for their mainframes. They wanted to have one of the steps in the first phase of their master release determine if the “distributed” and “mainframe” releases should be started. With a little scripting and using a recent blog (Using XL Release Gate Task for Deciding Future Tasks) we can make one release start another.
First lets setup our two templates that will be started by the master template. For our purposes here they don’t have to be very complicated. The first template will be for our distributed systems as follows:
Then we will add our template for mainframe installs as follows:
Finally, we will add a master template which we will start both. Depending on the path of the master template we can optionally start either one or both of the other two templates. Our master template will be as follows:
In the Master template, the first step is a gate to see which releases we need to start from this template. We are using the gate as a conditional step to decide future tasks. For more information about this technique read the blog “Using XL Release Gate Task for Deciding Future Tasks“. The second step is just a script to print out what was set in the “Determine Types of Installs” step. Next, the “Script” step actually determines which templates we selected in the first step and starts those releases. The code for the “Script” step is as follows:
import com.xebialabs.xlrelease.api.v1.forms
#
def gatesBeforeTask(task):
gatesList = []
for item in phase.tasks:
if str(item.getTaskType()) == "xlrelease.GateTask":
gatesList.append(item)
if item.id == task.id:
break
return gatesList
# End gatesBeforeTask
#
gates = gatesBeforeTask(task)
conditions = gates[0].getConditions()
#
for condition in conditions:
if condition.title == "isDistributed" and condition.isChecked():
templateName="Blog-Distributed"
template = templateApi.getTemplates( templateName )
print "Name = %s \n" % templateName
print "ID = %s \n" % template[0].id
sr = StartRelease()
sr.setReleaseTitle("New Distributed")
sr.releaseVariables={"myvar":"1"}
r = templateApi.start(template[0].id, sr)
print "Release ID = %s \n" % release.id
# End if
#
if condition.title == "isMainframe" and condition.isChecked():
templateName="Blog-Mainframe"
template = templateApi.getTemplates( templateName )
print "Name = %s \n" % templateName
print "ID = %s \n" % template[0].id
sr = StartRelease()
sr.setReleaseTitle("New Mainframe")
sr.releaseVariables={"yourvar":"1"}
r = templateApi.start(template[0].id, sr)
print "Release ID = %s \n" % release.id
# End if
# End for
This script task gets a list of “Gate” tasks into the array gates
. We know the gate where the types of release templates we want to start is in the first gate, so we get the conditions from that gate (i.e.gate[0]
). Since a gate can have multiple conditions, this is an array as well. The script next iterates over the list of conditions looking for the two we are interested in. When we find the proper conditions if they are set the template for that condition is started.
Some screen shots from the running Templates are as follows:
For this initial gate, if we only want one we need to select skip to move the release along.
Once the templates to start have been select the deployment can continue and start the other templates. In this example we only started the “Blog-Distributed” template. We can also open the running “Blog-Distributed” template and see it’s progress as follows:
The artifacts from this blog post are also in my Github repo at: https://github.com/zvercodebender/xebialabs-blog-files/tree/master/How_to_Start_one_Release_from_another_Release_in_XL_Release
Published at DZone with permission of Rick Broker, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments