Use the Python SDK to extend the Release plugin for Deploy

You can extend the functionality of the official Release plugin for Deploy by using xldeploy-py, the Python SDK for Deploy.

The SDK allows interaction with Deploy over the REST services and supports the following:

  • Deployfile
  • Deployment
  • Metadata
  • Package
  • Repository
  • Tasks

Each of the above services has specific methods that correspond to the REST services offered by Deploy.

Note: Not all methods and services available in the REST API are currently supported by the SDK. The SDK is customizable depending on the requirements of the clients using it.

Custom tasks

In Release, you can create custom tasks. A custom task contains an XML section that becomes part of the synthetic.xml in the ext folder of the Release server, and a Python file stored to a location adjacent to synthetic.xml. For more information, see How to Create Custom Task Types.

To extend the Release plugin for Deploy, you can create custom tasks that can retrieve items from Deploy or perform actions in Deploy using the SDK. These custom tasks can extend the xldeploy.XldTask to reuse properties required for any task related to Deploy.

Example of defining a custom task

Create a custom task to check if a CI exists on the Deploy Server. The new type to be included in synthetic.xml contains one new scriptLocation parameter representing the location of the python script within the ext directory. The other parameters are inherited from xldeploy.XldTask.

Modify the synthetic.xml

<type type="xld.CheckCIExist" extends="xldeploy.XldTask" label="XL-Deploy: Check CI exists" description="Custom Task to check if a CI exists">
    <property name="scriptLocation" default="CheckExists.py" hidden="true"/>
    <property name="ci_path" category="input" label="CI Path" required="true"/>
</type>

The CheckExists.py Python script referred to in the sample XML above can perform the required actions using the Python SDK. The official plugin already contains methods to create the xldeploy-py client. You must pass the server property of the task as an argument to method get_api_client(). The client returned can be used to call methods on any of the services mentioned above.

The CheckExists.py python script

from xlrxldeploy import *

client = get_api_client(task.getPythonScript().getProperty("server"))
path="some/path/to/a/ci"
print (client.repository.exists(path))