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.
import com.electriccloud.client.groovy.ElectricFlow
ElectricFlow ef = new ElectricFlow()
def value = ef.getProperty(propertyName: 'myParam')?.property?.value
def value = ef.setProperty(propertyName: 'myParam', value: 'test')
ef.setProperty('/myJobStep/summary', "My summary")
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
}
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.
To pack dependencies into plugin jar one can use ecpluginbuilder. Dependencies will be taken from lib/ folder and packed automatically.
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.
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'
}
}