Tasks within Sequential Groups

How can you loop through a group or container to get the tasks for that specific container?

It very easy to do at the release and phase level, but I just need references the to tasks within a sequential group.

Thanks in advance for any suggestions.

Hi Cindy, please provide some context.

Are you in a Jython script task?

What is it you are trying to acheive on a high level?


Hes Siemelink

I apologize for the lack of details for my question!

I have a phase in my release template where the first task in that phase is a Sequential Group that contains a manual task, a jython script task and a deploy task. The user enters an integer in the manual task, and the jython script looks for and duplicates the deploy task x-1 times, based upon the integer entered by the user. The new deploy tasks should be positioned at the end of the sequential group so that all deployments are done sequentially, before moving on to additional tasks in that phase. Since the release manager also has the option of adding an additional task at the beginning of the phase based upon their release process, I need to be able to derive the correct position of the new deploy tasks dynamically.

I added some debug code in my jython script to loop through the tasks in that phase to troubleshoot the issue, it just catches the Sequential Group - it doesn’t capture all of the tasks within that group. How do I capture a reference or count to the tasks within the group?

p = getCurrentPhase()
for t in p.tasks:
    ttype = str(t.getTaskType())
    print ttype
    print t.title
    if "Group" in ttype:
        for subt in t.tasks:
            subttype = str(subt.getTaskType())
            print subttype
            print subt.title


Thanks! I plugged this in and it worked perfectly!

1 Like

Hi Cindy, as a bonus I will throw in my ‘For each’ task that does something similar.

You can configure it with a list of values and a variable name.

When run, the For each task will create copies of the task just below it for each item in the list of values and a small script task that sets the variable accordingly.


<type type="xlr.ForEach" extends="xlrelease.PythonScript" label="Release flow: For each">
    <property name="values" category="input" kind="list_of_string"/>
    <property name="variable" category="input" />


def getTaskPosition(task):
    index = 1
    for t in task.container.tasks:
        if task.id == t.id:
            return index
        index += 1

position = getTaskPosition(task)

def addTaskToChangeVariable(value):
    scriptTask = taskApi.newTask("xlrelease.ScriptTask")
    scriptTask.script = "releaseVariables['{}'] = '{}'".format(variable, value)
    scriptTask.title = "Set variable to {}".format(value)
    scriptTask = phaseApi.addTask(task.container.id, scriptTask, position)

first = True
for value in values:

    if not first:
        task = getCurrentTask()
        copy = taskApi.copyTask(task.container.tasks[position - 1].id, task.container.id, position + 1)
        copy.title = task.container.tasks[position - 1].title
        first = False
    position += 2

Kind regards,

Hes Siemelink