Using the Force Migration Tool, we want to find out how to capture the asyncRequestId from our Salesforce deployments as an ANT property for use later in our ANT target.
For Example, I may deploy using my ANT target and the response will show:
Request ID for the current retrieve task: 09SR0000001BtJJMA0
Now I want to automatically cancel that deployment if the deploy time takes 2 hours using the sf:cancelDeploy task.
While I could copy/paste the request ID to cancel the deployment manually, how would I capture the returned asyncRequestId as an ANT Property?
Example Target Mock-Up:
<!-- Try to Deploying to Dev Sandbox, if it takes more than 2 hours cancel deployment-->
<target name="deployDEV">
<sf:deploy username="${dev.username}" password="${dev.password}" sessionId="${dev.sessionId}" serverurl="${dev.serverurl}" maxPoll="${dev.maxPoll}" deployRoot="src" testlevel="NoTestRun" rollbackOnError="true"/>
<property name="dev.asyncRequestId" value=" **[DEPLOYMENT'S REQUEST ID]** "/>
<condition **[2 HOURS PASSED AND DEPLOYMENT IS NOT DONE]**>
<sf:cancelDeploy username="${dev.username}" password="${dev.password}" sessionId="${dev.sessionId}" serverurl="${dev.serverurl}" maxPoll="${dev.maxPoll}" requestId="${dev.asyncRequestId}"/>
</condition>
</target>
Note that I specifically want to cancel the deployment rather than just let the build time out so that I can begin my next queued tests on CircleCI. Their hard 2 hour time limit causes cascading timeouts if one build time's out without being cancelled server-side.
In the Metadata API, it is really easy to get the ID like in the below example, but I'm not sure how to adapt it for ANT:
AsyncResult asyncResult = metadataConnection.deploy(zipBytes, deployOptions);
String asyncResultId = asyncResult.getId();