Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
expectedProjects = "HRWLSConfigurations,HRMDSObjects,HRSOAService,HRJavaApp,ValidatePaymentSB".split(",");

for (p in stgexec.getSnapshotProjects())
{
  if (!expectedProjects.contains(p.getProjectName()))
  {
    return "FAILED";
  }
}

return "SUCCESSFUL";

Deploy all projects sequentially across the target groups

This script will deploy the projects that are in the release one at a time to their target groups, one at a time. It will send all the projects and packages at the first priority level first, and then move on if none have failed to the next priority.

Code Block
import flexagon.fd.model.pojos.workflowrequest.*;
import flexagon.fd.model2.pojo.*;
import flexagon.fd.model.jaxb.releaseautomation.model.*;

def checkRunning(Long requestId){
  if(requestId == -1){
    return "DONE";
  }
    sleep(10000);
    List<WorkflowExecutionDataObject> wfes = FLEXDEPLOY.getWorkflowExecutionByWorkflowRequestId(requestId);
    for(wfe in wfes){
        if(wfe.getExecutionStatus() == 'Running' || wfe.getExecutionStatus() == 'Pending'){
            
            return "WAIT";
        }
        if(wfe.getExecutionStatus() == 'Failure'){
          return ("Deployment workflow execution " + wfe.getWorkflowExecutionId() + " for project " + wfe.getProjectId() + " failed.");
        }
    }
    return "DONE";
}

Long safeDeploy(Long projectId, String environmentCode, DeployOptions deployOptions){
  if(stgexecinfo.isUserSkipDeploy(projectId)){
    return -1;
  }

  deployOptions.setForce(stgexecinfo.isUserForceDeploy(projectId));
  
  try{
    return FLEXDEPLOY.deployProject(projectId,environmentCode,deployOptions);
  }catch(Exception e){
    if(e.getMessage() != null && e.getMessage().contains("FDML-00169")){
      return -1
    }
    return -2;
  }
}

RelSnapshotVersionDataObject findProjectVersionInfo(ReleaseProjectType p, projects){
  for (RelSnapshotVersionDataObject x in projects){
    if(x.getProjectId() == p.getProjectId() && x.getPackageName() == p.getPackageName()){
      return x;
    }
  }
  return null;
}

Map<Long, List<RelSnapshotVersionDataObject>> priorityLevels = new HashMap<>();
List<RelSnapshotVersionDataObject> projects = FLEXDEPLOY.getSnapshotDetails(SnapshotId).getVersionDataObjects()
for (p in stgexecinfo.getExecutionData().getReleaseProjects().getProject())
{
  RelSnapshotVersionDataObject rsvdo = findProjectVersionInfo(p, projects);
  if(rsvdo == null){
    //Skipping all utility projects. Those will not be run from this, so this is like deployall step.
    continue;
  }

  List<RelSnapshotVersionDataObject> prorityLevel = priorityLevels.getOrDefault(rsvdo.getPriority(), []);
  prorityLevel.add(rsvdo);
  priorityLevels.put(rsvdo.getPriority(), prorityLevel);
}
for (Map.Entry<Long, List<RelSnapshotVersionDataObject>> priorityLevel in priorityLevels)
{
  failed = [];
  for(rsvdo in priorityLevel.getValue())
  {
    DeployOptions deployOptions = new DeployOptions();
    deployOptions.setProjectStreamId(rsvdo.getProjectStreamId());
    deployOptions.setProjectVersionId(rsvdo.getProjectVersionId());
    if(!stgexecinfo.getInstanceOverride(rsvdo.getProjectId(),rsvdo.getPackageName()).isEmpty())
    {
      for( target in stgexecinfo.getInstanceOverride(rsvdo.getProjectId(),rsvdo.getPackageName()))
      {

        deployOptions.getInstanceIds().clear();
        deployOptions.getInstanceIds().add(FLEXDEPLOY.getTargetGroupByCode(target).getTargetGroupId())
        
        requestId = safeDeploy(rsvdo.getProjectId(),stgexec.getEnvironmentCode(),deployOptions);
        if(requestId == -2){
          failed += ("Could not deploy project " + rsvdo)
        }
        allDone = "WAIT";
        while (allDone == "WAIT")
        {
          //wait for it to finish before moving on to the next.
          allDone = checkRunning(requestId);
        }
        if(allDone != "DONE"){
          failed += allDone;
        }
      }
    } else
    {
      requestId = safeDeploy(rsvdo.getProjectId(),stgexec.getEnvironmentCode(),deployOptions);
        if(requestId == -2){
          failed += ("Could not deploy project " + rsvdo)
        }
      allDone = "WAIT";
      while (allDone == "WAIT")
      {
        //wait for it to finish before moving on to the next.
        allDone = checkRunning(requestId);
      }
      if(allDone != "DONE"){
        failed += allDone;
      }
    }
  }
  if (!failed.isEmpty()){
    throw new RuntimeException("" + failed.size() + " requests in priority group " + priorityLevel.getKey() + " failed. " + failed);
  }
}

Precondition Scripts

Execute Step Only for Specific Object Type

...