Context

3 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 regular perl HASH ref from parameters and config values.

Credentials from 'credential' parameter will be present in this hashref as user and password. Credentials, that have name like 'proxy_credential' will be mapped to 'proxy_user' and 'proxy_password' parameters.

Parameters

None

Returns

(HASH ref) 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.

my $simpleParams = $context->getRuntimeParameters();

Now, $simpleParams is:

{ # Values from config user => 'admin', password => '12345', proxy_user => 'proxy', proxy_password => 'qwerty', contentType => 'application/json', userAgent => 'Mozilla', # values from step parameters location => 'California', query => 'SELECT * FROM commander.plugins' }

getStepParameters()

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

Parameters

None

Returns

  • (FlowPDF::StepParameters) Parameters for the current step

Usage

my $params = $context->getStepParameters(); # this method returns a L<FlowPDF::Parameter> object, or undef, if no parameter with that name has been found. my $param = $params->getParameter('myStepParameter'); if ($param) { print "Param value is:", $param->getValue(), "\n"; }

getConfigValues()

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

Parameters

None

Returns

(FlowPDF::Config) Plugin configuration for current run context

Usage

my $configValues = $context->getConfigValues(); my $cred = $configValues->getParameter('credential'); if ($cred) { print "Secret value is: ", $cred->getSecretValue(), "\n"; }

newStepResult()

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

Parameters

None

Returns

(FlowPDF::StepResult) Object that can be used to process pipeline/procedure results.

Usage

my $stepResult = $context->newStepResult(); ...; $stepResult->apply();

newRESTClient($creationParams)

Initializes a FlowPDF::Client::REST object, applying components and other useful mechanisms to it during creation.

For now, this method supports following components and tools:

  • FlowPDF::Component::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, proxy component will be created automatically and all requests using FlowPDF::Client::REST methods will already have proxy enabled.

If debugLevel parameter is present in the configuration and is set to debug, debug mode for FlowPDF::ComponentProxy will become enabled.

  • 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 as "basic" credential with name as "basic_credential"

Parameters

(Optional) (HASHREF) FlowPDF::Client::REST Object creation params.

Returns

FlowPDF::Client::REST

Usage

my $rest = $context->newRestClient(); my $req = $rest->newRequest(GET => 'https://electric-cloud.com'); my $response = $rest->doRequest($req); print $response->decoded_content();

bailOut()

An advanced version of bailOut from FlowPDF::Helpers::bailOut. This version has connections with CloudBees CD and has following benefits:

  • Sets a Pipeline Summary.

  • Sets a JobStep Summary.

  • Sets outcome to Error.

  • Adds diagnostic messages to Diagnostic tab of the job.

  • Add suggestion if provided.

Parameters

(Required)(HASH ref) A hash reference with message and suggestion fields. Message is mandatory, suggestion is optional

Returns

None

Exceptions

None

Usage

This function is being used through context object. Also, note, that this function created it’s own FlowPDF::StepResult object. It means, that if this function is being used, no other L<FlowPDF::StepResult> objects will be auto-applied.

This function uses bailOut function from L<FlowPDF::Helpers> package and causes an exception, that could not be handled and your step will exit immedieately with code 1.

# this function will call an exit 1. $context->bailOut({ message => "File not found", suggestion => 'Please, check that you are using correct resource.' });