Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Start One Release From Another With XL Release

DZone's Guide to

How to Start One Release From Another With XL Release

· DevOps Zone ·
Free Resource

Can you release faster without sacrificing quality? See how with our free ebook Strategies for a Successful Test Automation Project and a free trial of Ranorex Studio today!

XL 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:

Screen Shot 2015-05-31 at 9.47.36 AM

Then we will add our template for mainframe installs as follows:

Screen Shot 2015-05-31 at 9.48.59 AM

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:

Screen Shot 2015-06-19 at 9.29.10 PM

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:

Screen Shot 2015-06-21 at 10.49.33 AM

For this initial gate, if we only want one we need to select skip to move the release along.

Screen Shot 2015-06-21 at 10.50.31 AM

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:

Screen Shot 2015-06-21 at 10.51.02 AM


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

Get your test automation project off to the right start. Download your free test planning template and a 30-day no-obligation trial of Ranorex Studio today!

Topics:
devops ,mainframe ,xl release

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}