Avloop creates an Application Version loop between any two versions of the Application on the stack, iterating through all the intervening versions.

NOTE: There is always an "implicit" avloop performed when deploying an Application Version to an Environment. In this case, the loop runs from the Application Version currently recorded as being on the target Environment to the Application Version being deployed. The variables ${dep.first}, ${dep.last}, ${dep.same}, ${dep.rollforward} and ${dep.rollback} are therefore available throughout the deployment process.


avloop has optional named parameters. These are:


from        Indicates the Application Version which should be used for the start of the loop. If this parameter is not present, DeployHub will look for the version of the Application on the target Environment. The value of "from" can either be a string indicating the name of the version, or an Application Version object.

to        Indicates the Application Version which should be used for the end of the loop. If this parameter is not present, DeployHub will use the Application Version being deployed or the Application Version on the stack. The value of "to" can either be a string indicating the name of the version or an Application Version object.


Both from and to parameters – if specified – must refer to versions of an Application on the stack. If an Application has been selected (for a deployment, approval or move for example) then the selected Application will already be on the stack. The avloop must refer to versions of this Application.


If you are running a stand-alone action, then you must select an Application in order to push it onto the stack. Failure to do so will result in a run-time error ("No Application on the Stack").


To use an Application other than that selected, you can put the avloop in a "using Application" statement – this will push the specified Application onto the stack.

Within the body of the loop, the following variables are set to indicate the status of the loop:


Variable Name

Value

${dep.rollforward}

true if the "to" version is later than the "from" version, false otherwise.

${dep.rollback}

true if the "to" version is earlier than the "from" version, false otherwise.

${dep.first}

true if this is the first time through the loop (the Application Version on the stack is the "from" version), false otherwise.

${dep.last}

true if this is the last time through the loop (the Application Version on the stack is the "to" version), false otherwise.

${dep.same}

true if the "to" version is the same as the "from" version.


avloop will examine the Application Version Graph to determine the route between the two Application Versions. There has to be a direct route between the from and to versions in order for the avloop to execute successfully. If there is no direct route then a runtime exception is thrown.


For example, consider the following version graph:



Example: Using Application Objects:


using Application "ITguys" {

// Ensure DayOneApp is on the stack

       set appfrom = getApplication("ITguys;1");

       set appto = getApplication("ITguys;3");

       if (${dep.rollforward}) {

               echo "Rolling Forward";

               } else {

                       echo "Rolling Back";

               }

       }

       avloop(from: $appfrom, to: $appto)

       {echo "${Application.name}}";

}//

// This will echo:

// Rolling Forward

// ITguys;1

// ITGuys;2

// ITGuys;3

//


Example: Using Application Version Names:


using Application "ITGuys" {

       // Ensure ITGuys is on the stack

avloop(from: "ITGuys;3", to: "ITGuys;1") {

if (${dep.rollforward}) {

echo "Rolling Forward";

} else {

echo "Rolling Back";

}

echo "${Application.name}";

}

}

//

// This will echo:

// Rolling Back

// ITguys;3

// Rolling Back

// ITGuys;2

// Rolling Back

// ITGuys;1

//


Example: No Direct Path - Error


using Application "ITGuys" {

               // There is not direct path between version 1a

               // and version 3 as they are on different branches

//

avloop(from: "ITGuys;1a", to: "ITGuys;3") {

       if (${dep.rollforward}) {

               echo "Rolling Forward";

} else {

       echo "Rolling Back";

}

       echo "${Application.name}";

}

}

//

// This will throw a Runtime Exception:

// There is no path between "ITGuys;1a" and "ITGuys;3"

//