Schedule Deployments with Apex

Overview 

AppOps provides the Apex Class “DeploymentSchedulable”   that you can call to schedule your deployments. Pass in the data set ID, and source and destination org IDs to schedule automatic deployments.

These steps provide one way to implement deployment scheduling:

  1. Open the Developer Console.
  2. Navigate to Debug > Open Execute Anonymous Window.
  3. Copy and paste this code.

Schedulable Service Methods

Provides wrappers to schedule deployments.

global with sharing class AppOpsDeploymentSchedulableService implements Schedulable { 
    global AppOpsDeploymentSchedulableService(AppOpsWebServices.DeploymentServiceRequestV1 deploymentServiceRequest, 
        String destinationManagedInstanceId);
}

Sample Code

Schedules a deployment.

//Construct deployment request, empty for brevity 
AppOpsWebServices.DeploymentServiceRequestV1 deploymentServiceRequest = 
  new AppOpsWebServices.DeploymentServiceRequestV1();
String destinationManagedInstanceId = 'e1738072-f9fd-4d6a-8278-35fde79c85a9';

AppOpsDeploymentSchedulableService sch = 
  new AppOpsDeploymentSchedulableService(deploymentServiceRequest, destinationManagedInstanceId);   
String chron = '0 0 23 * * ?';        
System.schedule('AppOps Deployment', chron, sch);
  1. Modify the code to use the appropriate constructor (refer to the screenshot for choices) and schedule string.
  2. Modify <data set name> and <connection name> in the query strings to match your names.
  3. Execute the code.