How to Start One Release from another with XL Release
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: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 forThis 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: