Versions Compared

Key

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

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.

Table of Contents

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 instance 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.

...

Override deploy

...

target group on all projects with Plugin suffix in name
Code Block
languagegroovy
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 instance target group for projects with type EBS. This could be used as a custom gate or step.

Code Block
theme
languagegroovyRDark
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');
    	}
	}
}

...

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.

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

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

return "SUCCESSFUL";

...

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

Code Block
languagegroovythemeRDark
def deployedTypes = stgexec.getProjectWorkflowOutputValues("DeployedTypes");

for (String listItem : deployedTypes)
{   
  if (listItem.contains('OAF_JAVA'))
  {
    return true;
  }
}

return false;

...

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.

Code Block
languagegroovythemeRDark
def projectGroup = "Oracle Integrations"
return stgexec.getSnapshotProjects().findIndexOf { 
  projectGroup in it.getProjectGroupNames() 
} != -1

...