...
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); } } |
Change Workflows and Target Groups for all the projects in a specific folder.
This is useful when you have many projects in a folder, that will have the same build/deploy workflow, and the same build and deploy instance.
Code Block |
---|
import flexagon.fd.model.pojos.rest.topology.integrations.SCMInstancePojo;
import flexagon.fd.model.pojos.rest.properties.PropertyValuePojo;
import flexagon.fd.model.pojos.rest.project.*;
import flexagon.fd.core.enums.SCMTypeEnum;
import flexagon.fd.core.enums.ProjectTypeEnum;
import flexagon.fd.model.pojos.rest.properties.PropertyValuePojo;
import flexagon.fd.model.pojos.folder.*;
import flexagon.fd.model2.pojo.ProjectDataObject;
import flexagon.fd.services.groovy.functions.*;
FlexDeploy2Functions FLEXDEPLOY = new FlexDeploy2Functions();
def projectDataObject = new ProjectDataObject();
projectDataObject.setFolderId(8996557);
def resProjects = FLEXDEPLOY.searchProjects(projectDataObject,10,0).getItems();
def proj = new ProjectPojo();
def buildInfo = new ProjectBuildInfo();
def deployInfo = new ProjectDeployInfo();
buildInfo.setWorkflowId(675528L);
buildInfo.setInstanceId(303656L);
deployInfo.setWorkflowId(5885144L);
deployInfo.setInstanceIds([303656L]);
proj.setBuildInfo(buildInfo);
proj.setDeployInfo(deployInfo);
for(def project:resProjects)
{
def projectId = project.getProjectId();
FLEXDEPLOY.patchProject(projectId, proj);
} |
Precondition Scripts
Execute Step Only for Specific Object Type
...