Valid since:
XL Deploy 4.5.0

When you define an XML or script rule, you use expressions or scripts to define its behavior. These are written in Jython, a combination of Python and Java.

Objects available to rules

The data that is available for a planning script to use depends on the scope of the rule. This table shows when each object is available:

Object name Type Scope Description
context DeploymentPlanningContext all Use this to add steps and checkpoints to the plan.
deployedApplication DeployedApplication all Specifies which application version will be deployed to which environment.

In XL Deploy 5.1.0 and later, deployedApplication is not available in the case of DESTROY.
previousDeployedApplication DeployedApplication all In XL Deploy 5.1.0 and later, this is the previous application version that was deployed.

In XL Deploy 5.0.x and earlier, previousDeployedApplication is not available.
steps   all Allows you to create steps from the step registry.
specification DeltaSpecification pre-plan
post-plan
Contains the delta specification for the current deployment.
delta Delta deployed Whether the deployed should be created, modified, destroyed, or left unchanged (NOOP).
deployed Deployed deployed In XL Deploy 4.5.3, 5.0.0, and later, and in the case of CREATE, MODIFY, or NOOP, this is the “current” deployed that the delta variable refers to; in the case of DESTROY, it is not provided.

In XL Deploy 4.5.2 and earlier, and in the case of CREATE, MODIFY, or NOOP, this is the “current” deployed that the delta variable refers to; in the case of DESTROY, this is the “old” deployed.
previousDeployed previousDeployed deployed In XL Deploy 4.5.3, XL Deploy 5.0.0, and later, and in the case of MODIFY, DESTROY, or NOOP, this is the “previous” deployed that the delta variable refers to; in the case of CREATE, this is not provided.

In XL Deploy 4.5.2 and earlier, previousDeployed is not available.
deltas Deltas plan Collection of all Deltas in the current InterleavedPlan.
controlService ControlService all Gives you access to the ControlService.
deploymentService DeploymentService all Gives you access to the DeploymentService.
inspectionService InspectionService all Gives you access to the InspectionService.
metadataService MetadataService all Gives you access to the MetadataService.
packageService PackageService all Gives you access to the PackageService.
permissionService PermissionService all Gives you access to the PermissionService.
repositoryService RepositoryService all Gives you access to the RepositoryService.
roleService RoleService all Gives you access to the RoleService.
serverService ServerService all Gives you access to the ServerService.
taskService TaskService all Gives you access to the TaskService.
taskBlockService TaskBlockService all Gives you access to the TaskBlockService.
userService UserService all Gives you access to the UserService.
logger Logger all Allows you to access the XL Deploy logs. Prints logs to namespace com.xebialabs.platform.script.Logging.

Note: These objects are not automatically available for execution scripts, such as in the jython or os-script step. If you need an object in such a step, the planning script must make the object available explicitly; for example, by adding it to the jython-context map parameter in the case of a jython step.

Accessing CI properties

To access configuration item (CI) properties, including synthetic properties, use the property notation. For example:

name = deployed.container.myProperty

You can also refer to a property in the dictionary style, which is useful for dynamic access to properties. For example:

propertyName = "myProperty"
name = deployed.container[propertyName]

For full, dynamic read-write access to properties, you can access properties through the values object. For example:

deployed.container.values["myProperty"] = "test"

Accessing deployeds

In the case of rules with the plan scope, the deltas object will return a list of delta objects. You can get the deployed object from each delta.

The delta and delta specification expose the previous and current deployed. To access the deployed that is going to be updated, use the deployedOrPrevious property:

depl = delta.deployedOrPrevious
app = specification.deployedOrPreviousApplication

Comparing delta operations and types

You can compare a delta operation to the constants "CREATE", "DESTROY", "MODIFY" or "NOOP" as follows:

if delta.operation == "CREATE":
    pass

You can compare the CI type property to the string representation of the fully qualified type:

if deployed.type == "udm.Environment":
    pass