How to perform a complete deployment from beginning to end via XL Deploy using REST API?

Follow

Shashank Srivastava -

Scenario
You are trying to automate the deployment process & wish to perform all the deployment steps using REST API calls only without involving any GUI.
Environment

XL Deploy, REST API.

Steps to Perform

1. Gather information about Environment & the Application version.

As we know, a typical deployment starts with an Initial Deployment window in XL Deploy GUI. This is where you drag & drop your package and the environment where you want to deploy to.

So, the first step will be to tell REST API about the Environment & the Application version. For this, run a GET call against this : -

http://localhost:4516/deployit/deployment/prepare/initial?environment=Environments/LocalHost&version=Applications/fileApp/1.0

You can see that my Environment here is LocalHost & I am deploying an Application version called Applications/fileApp/1.0.

It will produce below output : - Make sure you copy this output since we are going to need it in subsequent steps.

<deployment id="deployment-cb799c52-2567-425d-8ace-0096a9f1f81f" type="INITIAL">
<deploymentGroupIndex>0</deploymentGroupIndex>
<application>
<udm.DeployedApplication id="Environments/LocalHost/fileApp">
<version ref="Applications/fileApp/1.0"/>
<environment ref="Environments/LocalHost"/>
<deployeds/>
<orchestrator/>
<optimizePlan>true</optimizePlan>
<boundConfigurationItems/>
<unresolvedPlaceholders/>
<undeployDependencies>false</undeployDependencies>
</udm.DeployedApplication>
</application>
<deployeds/>
<deployables>
<ci ref="Applications/fileApp/1.0/FileApp" type="file.File"/>
</deployables>
<containers>
<ci ref="Infrastructure/LocalHost" type="overthere.LocalHost"/>
</containers>
<requiredDeployments/>
</deployment>

2. Map the Application to the particular container.

Next step in GUI is to map the Application to the particular container. XL Deploy does it automatically now but we need to tell REST API about this.

For this, run below POST call by selecting content-type as Application/XML & sending below payload. This is the same payload that you copied from step #1.

http://localhost:4516/deployit/deployment/previewblock

Payload to be sent : -

<deployment id="deployment-78f18844-9106-4637-80de-54e61cdde8f9" type="INITIAL">
<deploymentGroupIndex>0</deploymentGroupIndex>
<application>
<udm.DeployedApplication id="Environments/LocalHost/fileApp">
<version ref="Applications/fileApp/1.0"/>
<environment ref="Environments/LocalHost"/>
<deployeds/>
<orchestrator/>
<optimizePlan>true</optimizePlan>
<boundConfigurationItems/>
<unresolvedPlaceholders/>
<undeployDependencies>false</undeployDependencies>
</udm.DeployedApplication>
</application>
<deployeds/>
<deployables>
<ci ref="Applications/fileApp/1.0/FileApp" type="file.File"/>
</deployables>
<containers>
<ci ref="Infrastructure/LocalHost" type="overthere.LocalHost"/>
</containers>
<requiredDeployments/>
</deployment>

It will produce output similar to below : -

<previewblock id="deployment-78f18844-9106-4637-80de-54e61cdde8f9">
<block id="0" state="PENDING" description="" hasSteps="true" root="true">
<block id="0_1" state="PENDING" description="" hasSteps="true" phase="true">
<block id="0_1_1" state="PENDING" description="Register changes for fileApp" hasSteps="true" current="0">
<step failures="0" state="PENDING" skippable="false">
<description>Register deployeds</description>
<log></log>
<metadata>
<rule/>
<previewAvailable>false</previewAvailable>
<order>100</order>
</metadata>
</step>
</block>
</block>
</block>
</previewblock>

3. Prepare deployeds.

Now, its time to prepare the deployeds for our deployment. Here we are telling REST API that it must prepare the deployeds with all the properties they may have. For example, resolve the dictionary(as you can see in my example below) or checking the TargetPath.

Run the below POST call with the payload mentioned beneath it.

http://localhost:4516/deployit/deployment/prepare/deployeds

Payload : -

<deployment id="deployment-cb799c52-2567-425d-8ace-0096a9f1f81f" type="INITIAL">
<deploymentGroupIndex>0</deploymentGroupIndex>
<application>
<udm.DeployedApplication id="Environments/LocalHost/fileApp">
<version ref="Applications/fileApp/1.0"/>
<environment ref="Environments/LocalHost"/>
<deployeds/>
<orchestrator/>
<optimizePlan>true</optimizePlan>
<boundConfigurationItems/>
<unresolvedPlaceholders/>
<undeployDependencies>false</undeployDependencies>
</udm.DeployedApplication>
</application>
<deployeds/>
<deployables>
<ci ref="Applications/fileApp/1.0/FileApp" type="file.File"/>
</deployables>
<containers>
<ci ref="Infrastructure/LocalHost" type="overthere.LocalHost"/>
</containers>
<requiredDeployments/>
</deployment>

It will produce output similar to : - Copy this output as we will need it in step #5.

<deployment id="deployment-cb799c52-2567-425d-8ace-0096a9f1f81f" type="INITIAL">
<deploymentGroupIndex>0</deploymentGroupIndex>
<application>
<udm.DeployedApplication id="Environments/LocalHost/fileApp">
<version ref="Applications/fileApp/1.0"/>
<environment ref="Environments/LocalHost"/>
<deployeds/>
<orchestrator/>
<optimizePlan>true</optimizePlan>
<boundConfigurationItems/>
<unresolvedPlaceholders/>
<undeployDependencies>false</undeployDependencies>
</udm.DeployedApplication>
</application>
<deployeds>
<file.DeployedFile id="Infrastructure/LocalHost/FileApp">
<deployable ref="Applications/fileApp/1.0/FileApp"/>
<container ref="Infrastructure/LocalHost"/>
<placeholders/>
<targetPath>/tmp</targetPath>
<targetPathShared>true</targetPathShared>
<createTargetPath>false</createTargetPath>
</file.DeployedFile>
</deployeds>
<deployables>
<ci ref="Applications/fileApp/1.0/FileApp" type="file.File"/>
</deployables>
<containers>
<ci ref="Infrastructure/LocalHost" type="overthere.LocalHost"/>
</containers>
<requiredDeployments/>
</deployment>

You can see in above output that my Placeholder was resolved & TargetPath was substituted with value /tmp.

4. Validate the deployment.

We will now ask REST API to validate the deployment. For this run below POST call with the payload mentioned beneath it. You will notice that payload being sent has been the same in all the steps.

http://localhost:4516/deployit/deployment/validate

Payload : -

<deployment id="deployment-cb799c52-2567-425d-8ace-0096a9f1f81f" type="INITIAL">
<deploymentGroupIndex>0</deploymentGroupIndex>
<application>
<udm.DeployedApplication id="Environments/LocalHost/fileApp">
<version ref="Applications/fileApp/1.0"/>
<environment ref="Environments/LocalHost"/>
<deployeds/>
<orchestrator/>
<optimizePlan>true</optimizePlan>
<boundConfigurationItems/>
<unresolvedPlaceholders/>
<undeployDependencies>false</undeployDependencies>
</udm.DeployedApplication>
</application>
<deployeds/>
<deployables>
<ci ref="Applications/fileApp/1.0/FileApp" type="file.File"/>
</deployables>
<containers>
<ci ref="Infrastructure/LocalHost" type="overthere.LocalHost"/>
</containers>
<requiredDeployments/>
</deployment>

Output here will be similar to the payload sent.

5. Execute deployment.

This is the last step & here the payload being sent will be the one that has complete deployment information like Placeholders & other properties. For this, we had already copied the output we had from step #3.

Run below POST call by supplying the output/payload copied from step #3.

http://localhost:4516/deployit/deployment/

Payload

<deployment id="deployment-cb799c52-2567-425d-8ace-0096a9f1f81f" type="INITIAL">
<deploymentGroupIndex>0</deploymentGroupIndex>
<application>
<udm.DeployedApplication id="Environments/LocalHost/fileApp">
<version ref="Applications/fileApp/1.0"/>
<environment ref="Environments/LocalHost"/>
<deployeds/>
<orchestrator/>
<optimizePlan>true</optimizePlan>
<boundConfigurationItems/>
<unresolvedPlaceholders/>
<undeployDependencies>false</undeployDependencies>
</udm.DeployedApplication>
</application>
<deployeds>
<file.DeployedFile id="Infrastructure/LocalHost/FileApp">
<deployable ref="Applications/fileApp/1.0/FileApp"/>
<container ref="Infrastructure/LocalHost"/>
<placeholders/>
<targetPath>/tmp</targetPath>
<targetPathShared>true</targetPathShared>
<createTargetPath>false</createTargetPath>
</file.DeployedFile>
</deployeds>
<deployables>
<ci ref="Applications/fileApp/1.0/FileApp" type="file.File"/>
</deployables>
<containers>
<ci ref="Infrastructure/LocalHost" type="overthere.LocalHost"/>
</containers>
<requiredDeployments/>
</deployment>

It will complete the deployment & will give you a Deployment ID, as shown in output below.

cddbc988-934a-4893-b62d-e964799a75f9

You can see this in Task Monitor of XL Deploy GUI. This ID can then be started using TaskService.

Caveats (if any)

All steps (except step #1) here need content-type as Application/XML. So make sure you select this in your REST client or as a parameter in -X if you are using cURL command.

 

Additional Information

More information can be had from this XebiaLabs forum post.

Tags
 xl-deploy, how-to, REST, deployment
Have more questions? Submit a request
Powered by Zendesk