Skip to main content

This post is from the XebiaLabs blog and has not been updated since the original publish date.

Last Updated Jun 21, 2015 — DevOps Expert

How to Start One Release from another with XL Release

DevOps

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 AMThen we will add our template for mainframe installs as follows:Screen Shot 2015-05-31 at 9.48.59 AMFinally, 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 PMIn 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 AMFor 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 AMOnce 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 AMThe 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 

More from the Blog

View more
Feb 22, 2021

Reckoning DevOps’ role in the enterprise value stream

DevOps
If you’re a software or digital solutions company, you may use DevOps ...
Read More
Feb 10, 2021

Customer spotlight: Schneider avoiding bumps in the road with DevOps adoption

DevOps
Everyone wants to deliver software faster and more reliably. Companies ...
Read More
Jan 06, 2021

How testing automation can build a culture of QA while accelerating continuous delivery

DevOps
An organization’s level of automated test coverage is quickly emerging ...
Read More
Jul 30, 2020

Part 2: Is Technology Slowing Down Your Digital Transformation?

DevOps
In part one of this post, we shared insights from Andreas Prins’ webin ...
Read More
Contact Us