Context

2 minute readReferenceExtensibilityDeveloper productivity

This class provides methods to access procedure parameters, config values and process the output of a step result from the current run context.

getRuntimeParameters()

A simplified accessor for the step parameters and config values. This method returns a StepParameters instance built from parameters and config values.

Parameters

None

Returns

(StepParameters) A merged parameters from step parameters and config values.

Usage

Assume procedure form.xml contains 'query' and 'location' parameters and config contains 'credential', 'proxy_credential', 'contentType' and 'userAgent'. See this snippet as to how you can retrieve runtime parameters.

StepParameters simpleParams = context.getRuntimeParameters()

Now, you can access both configuration and step parameters from a single object:

// Step parameters String query = simpleParams.getParameter('query').getValue() String location = simpleParams.getParameter('location').getValue() // Config values String contentType = simpleParams.getParameter('contentType').getValue() String userAgent = simpleParams.getParameter('userAgent').getValue() Credential cred = simpleParams.getCredential('credential') Credential proxyCred = simpleParams.getCredential('proxy_credential')

Or:

Map paramsMap = context.getRuntimeParameters().getAsMap() // Step parameters String query = paramsMap['query'] String location = paramsMap['location'] // Config values String contentType = paramsMap['contentType'] String userAgent = paramsMap['userAgent'] Credential cred = paramsMap['credential'] Credential proxyCred = paramsMap['proxy_credential']

getStepParameters()

Returns a StepParameters object which can be used to access current step parameters. This method does not require parameters.

Parameters

None

Returns

  • (StepParameters) Parameters for the current step

Usage

StepParameters params = context.getStepParameters() // this method returns a Parameter object, or null if no parameter with that name has been found. Parameter param = params.getParameter('myStepParameter') if (param != null) { println("Param value is: " + param.getValue()) }

getConfigValues()

This method returns a Config object, which represents plugin configuration. This method does not require parameters.

Parameters

None

Returns

(Config) Plugin configuration for current run context

Usage

Config configValues = context.getConfigValues() Credential cred = configValues.getCredential('credential') if (cred != null) { println("Secret value is: " + cred.getSecretValue()) }

newStepResult()

This method returns a StepResult object which can be used to process the output returned by a procedure or pipeline stage.

Parameters

None

Returns

(StepResult) Object that can be used to set the pipeline/procedure results.

Usage

StepResult stepResult = context.newStepResult() ...; stepResult.setOutputParameter('deployed', 'true') stepResult.apply()

newRESTClient()

Initializes a REST object, providing the configuration values to it.

For now, this method supports following components and tools:

  • Proxy

    Proxy can be automatically be enabled by making sure that following parameters are present in the configuration: +

    • credential with the proxy_credential name.

    • regular parameter with httpProxyUrl name + If configuration has all fields above, the proxy parameters will be set on the HTTPBuilder instance. If the 'proxy_credential' is not empty, the 'Proxy-Authorization' header will be added to every request.

  • Basic Authorization Basic authorization can be automatically applied to all REST requests. In order to enable it make sure that the following parameters are present in your plugin configuration:

    • 'authScheme' parameter with value "basic"

    • credential with name "basic_credential"

Parameters

None

Returns

Configured REST instance

Usage

REST rest = context.newRestClient() def req = rest.newRequest([method: 'GET', path: '/api/v2/query']) def response = rest.doRequest(req) println(response.toString())