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 Instance on All Projects with Plugin Suffix in Name

The following script uses the setInstanceOverride method to set the deploy instance 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 Instance Based on Project Type

In this scenario, the pipeline should only be deploying to the EBS instance 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');
    	}
	}
}