Question
How can we use a script to remove the deployed application from environments?
Answer
You can use the REST API in the script to undeploy the application.
Steps to Follow
- Generate the task ID of undeploy. The deployment id from the result below is the task ID of undeploy:
Command
curl --location --request GET 'http://192.168.56.101:4516/xldeploy/deployment/prepare/
Result
undeploy? deployedApplication=Environments/restapitest/testapispace' \ -header
'Authorization: Basic YWRtaW46YWRtaW4='
<deployment id="9eb5030e-4264-4836-842c-761a011270b0" type="UNDEPLOYMENT">
<deploymentGroupIndex>0</deploymentGroupIndex>
<application>
<udm.DeployedApplication id="Environments/restapitest/testapispace" token="37f61da3-2a82
-4e1a
-90c3-0c8e38b508c8" created-by="admin" created-at="2022-02-16T09:16:32.617+0000" last-
modified-by="admin" last-modified-at="2022-02-16T09:16:32.617+0000">
<version ref="Applications/testapispace/testapispaceD"/>
<environment ref="Environments/restapitest"/>
<deployeds>
<ci ref="Infrastructure/restapitest/testapispaceF"/>
</deployeds>
<orchestrator/>
<optimizePlan>true</optimizePlan>
<boundConfigurationItems/>
<unresolvedPlaceholders/>
<undeployDependencies>false</undeployDependencies>
<allowConcurrentDeployments>true</allowConcurrentDeployments>
</udm.DeployedApplication>
</application>
<deployeds/>
<deployables>
<ci ref="Applications/testapispace/testapispaceD/testapispaceF" type="file.File"/>
</deployables>
<containers>
<ci ref="Infrastructure/restapitest" type="overthere.LocalHost"/>
</containers>
<resolvedPlaceholders/>
<requiredDeployments/>
</deployment> - Use the result above as the payload to create the task ID of this activity. Please make sure to change the value in the URL from /xldeploy/ to /deployit/:
Command
curl --location --request POST 'http://192.168.56.101:4516/deployit/deployment' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Content-Type: application/xml' \
--header 'Cookie: XSRF-TOKEN=808e7945-35c6-464c-8bcf-1fdcbf73dd49' \
--data-raw '<deployment id="9eb5030e-4264-4836-842c-761a011270b0" type="UNDEPLOYMENT">
<deploymentGroupIndex>0</deploymentGroupIndex>
<application>
<udm.DeployedApplication id="Environments/restapitest/testapispace" token="37f61da3-2a82
-4e1a-90c3-0c8e38b508c8" created-by="admin" created-at="2022-02-16T09:16:32.617+0000"
last-modified-by="admin" last-modified-at="2022-02-16T09:16:32.617+0000">
<version ref="Applications/testapispace/testapispaceD"/>
<environment ref="Environments/restapitest"/>
<deployeds>
<ci ref="Infrastructure/restapitest/testapispaceF"/>
</deployeds>
<orchestrator/>
<optimizePlan>true</optimizePlan>
<boundConfigurationItems/>
<unresolvedPlaceholders/>
<undeployDependencies>false</undeployDependencies>
<allowConcurrentDeployments>true</allowConcurrentDeployments>
</udm.DeployedApplication>
</application>
<deployeds/>
<deployables>
<ci ref="Applications/testapispace/testapispaceD/testapispaceF" type="file.File"/>
</deployables>
<containers>
<ci ref="Infrastructure/restapitest" type="overthere.LocalHost"/>
</containers>
<resolvedPlaceholders/>
<requiredDeployments/>
</deployment>'Result
9eb5030e-4264-4836-842c-761a011270b0
- Once step 2 managed to print out the task ID successfully, you can start the task ID. Please update the URL "/xldeploy/" to "/deployit/" and add the task ID in the URL before "/start:
Command
curl --location --request POST 'http://192.168.56.101:4516/deployit/tasks/v2/9eb5030e-
4264-4836-842c-761a011270b0/start' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Cookie: XSRF-TOKEN=808e7945-35c6-464c-8bcf-1fdcbf73dd49'Result
It will not print out anything and the status of REST API call will return as 200 (success)
Related Information
XL Deploy REST API 9.0 undeploy application
Comments
Please sign in to leave a comment.