Groovy based Plugin - electric-cloud/PluginWizard GitHub Wiki

First of all, your plugin can contain procedures that use any shell and any combination of them. Common shells are:

  • ec-groovy
  • ec-perl

For Groovy, library ElectricFlow is available by default (starting 8.2 version of ElectricFlow). See Groovy API Guide.

Code Snippets

Getting a parameter value

import com.electriccloud.client.groovy.ElectricFlow
ElectricFlow ef = new ElectricFlow()

def value = ef.getProperty(propertyName: 'myParam')?.property?.value

Setting a property

def value = ef.setProperty(propertyName: 'myParam', value: 'test')

Setting a summary

ef.setProperty('/myJobStep/summary', "My summary")

Getting configuration values

Please note that the credential should be attached to the step which is calling getFullCredential API. To attach a credential to a step one can declare it in the promote.groovy like the following:

def stepsWithAttachedCredentials = [
    [
        procedureName: '<Procedure Name>',
        stepName: '<Step Name>'
    ],
]

Code to get the configuration parameters alongside with the credentials:

def getConfiguration(configName) {
    Map configuration = ef.getProperties(path: '/projects/@PLUGIN_NAME@/ec_plugin_cfgs/' + configName)?.propertySheet?.property?.collectEntries {
        [it.propertyName, it.value]
    }
    def credential = ef.getFullCredential(credentialName: configName)
    configuration.userName = credential?.credential?.userName
    configuration.password = credential?.credential?.password
    return configuration
}

Storing Third-Party Dependencies

We are using Grape dependency management. If the dependency is not found in the $COMMANDER_HOME/utils/langs, it would be loaded into this folder. To make plugin self-contained, dependencies can be stored in artifacts and retrieved into utils/langs folder during procedure execution.

Pack Dependencies into Plugin .jar

To pack dependencies into plugin jar one can use ecpluginbuilder. Dependencies will be taken from lib/ folder and packed automatically.

Store Artifact on EF Server (Promotion)

Packed dependencies are turned into EF artifacts during plugin promotion. It means that the code should be included into ec_setup.pl. The provided ec_setup.pl already has the logic to process dependencies and turn them into artifacts named @PLUGIN_NAME@-Grapes.

Retriving an Artifact During Procedure Execution

All procedures that have third-party dependencies should have a first "Setup" step. This step will retrieve an artifact from the EF artifact storage and place it into utils/langs folder. This boilerplate has a procedure "Setup" for this.

The procedure.dsl will look like this:

def procName = 'groovyProcedureTemplate'
procedure procName, description: 'Sample Groovy-based procedure', {
    step 'Setup', {
        subprocedure = 'Setup'
    }

    step 'step1', {
        command = new File(pluginDir, "dsl/procedures/$procName/steps/step1.groovy").text
        shell = 'ec-groovy'
    }
}
⚠️ **GitHub.com Fallback** ⚠️