Groovy Script Examples

A groovy script can be used in custom gates and steps, as well as for many configuration values on specific steps or gates. Additionally, a gate or step can be skipped by providing a Precondition groovy script. This page includes some sample scripts for these scenarios. See Pipeline Groovy Variables and Methods for a full listing of the accessible variables and methods in these groovy scripts.

Custom Gates and Steps

Override Deploy Target Group on All Projects with Plugin Suffix in Name

The following script uses the setInstanceOverride method to set the deploy target group on the stage for each project in the snapshot with 'Plugin' at the end of the name. This could function as a custom gate or step.

snapshotProjects=stgexec.getSnapshotProjects(); for(snapshotProject in snapshotProjects) { if(snapshotProject.getProjectName().endsWith("Plugin")) { stgexecinfo.setInstanceOverride(snapshotProject.getProjectId(), "WEBLOGIC") } }

Override Deploy Target Group Based on Project Type

In this scenario, the pipeline should only be deploying to the EBS target group for projects with type EBS. This could be used as a custom gate or step.

def projects = stgexec.getSnapshotProjects(); for (def project in projects) { if (project.getProjectType() != null) { if ('EBS'.equals(project.getProjectType())) { stgexecinfo.setInstanceOverride(project.getProjectId(), project.getPackageName(), 'EBS'); } } }

Validate Snapshot Contents

A pipeline can prevent deployments of any unexpected projects in the snapshot with a script similar to the following. This would best be implemented as a custom gate in the first stage of the pipeline.

expectedProjects = "HRWLSConfigurations,HRMDSObjects,HRSOAService,HRJavaApp,ValidatePaymentSB".split(","); for (p in stgexec.getSnapshotProjects()) { if (!expectedProjects.contains(p.getProjectName())) { throw new RuntimeException("Project: " + p.getProjectName() + " was not expected."); } } 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.

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.

Precondition Scripts

Execute Step Only for Specific Object Type

This could be used to conditionally call a Restart OACore or Generate Jar utility workflow only if OAF_JAVA files are deployed.

Execute Gate only if Snapshot Projects contain a specific Project Group

This is useful when you could want technology/team specific approvals which would only make sense to do when that particular Project Group/Technology is included in the snapshot.

Create Comments

Use FLEXDEPLOY function createComment with FdCommentDataObject as an argument to create comment. FdCommentDataObject contains commentId, objectId, commentText, parentObjectId, objectType and versionNumber.

The below table will explain the Object Types supported and inputs that needs to be passed based on the type.

Object Type

Object Id

Parent Object Id

Object Type

Object Id

Parent Object Id

PIPELINE_GATE_EXEC

Pipeline stage gate id

Pipeline exec id

PIPELINE_STEP_EXEC

Pipeline stage step id

Pipeline exec id

PIPELINE_GATE

Pipeline stage gate id

 

PIPELINE_STEP

Pipeline stage step id

 

RELEASE

Release definition id

 

WORKITEM

Flx WorkItem id

 

Below sample script creates a comment for pipeline gate execution object type.

Release Methods from FlexDeploy2Functions class

public List<RelProjectDataObject> createReleaseProjects(Long pReleaseId, List<RelProjectDataObject> pPojos)

Use FLEXDEPLOY function createReleaseProjects with List<RelProjectDataObject> as an argument to create release projects.
RelProjectDataObject contains RelProjectId, BuildEnvironmentId, ProjectId, ProjectBranchId, RelDefinitionId, PackageName, ProjectGroups, DeployPriority

Prepare the RelProjectDataObject with above details and pass into the createReleaseProjects.

Above method can create multiple release projects in the release. If you want to create only one project in the release, then you can use the below method.

public RelProjectDataObject createReleaseProject(RelProjectDataObject pPojo)

Below sample script adds the project to release.

public RelProjectDataObject patchReleaseProject(RelProjectDataObject pRelProjectDataObj)

Use FLEXDEPLOY function to patch the Release Project details. It should take RelProjectDataObject as an argument to patch the release project details.

Prepare the RelProjectDataObject with RelDefinitionId and other required filed to be patched.

Below sample script can patch the release project details.

public RelDefinitionDataObject copyRelease(CopyReleaseInput pCopyReleaseInput)

Use FLEXDEPLOY function copy Release that copies from source release details to the target or new release. created through copyRelease function.
It takes CopyReleaseInput as an argument. CopyReleaseInput contains SourceRelDefinitionId, TargetFolderId, TargetReleaseName along with boolean type inputs are CopyTags, CopyWorkItems, CopyProjects, CopyOverridenRoleMembers, CopyOverridenSettings. Boolean type fields are optional, by default they are set to false so if any of those fields are set to true then those will be copied from source release to target release.

Below sample script can create a target release from the source release details.

 

The following macros are not currently supported in the footer:
  • style