Rule objects and properties

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

Objects that can have rules applied

The data available for a planning script 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. Not available in the case of DESTROY.
previousDeployedApplication DeployedApplication all This is the previous application version that was deployed.
steps all Enables you to create steps from the step registry. For more information, see Use a predefined step in a rule.
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 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.
previousDeployed Deployed deployed 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.
deltas Deltas plan Collection of every Delta 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 Provides access to 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. For more information, see Plan scope and Deltas.

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