Manage post-processing scripts
This topic explains how Deployment Automation handles post-processing in component processes. You can create and use your own post-processing scripts.
Guidelines for post-processing scripts
Component processes perform post-processing whenever a plugin step finishes running. Typically, post-processing scripts help ensure that expected results occurred.
When configuring a process step, you can use your custom script created in JavaScript.
When a process step finishes, the agent performing the step runs your script:
-
The agent loads the server log file and finds the exit code property of the target step using regular expressions from the script. For details, see View the output log.
-
Before processing the next step, the agent applies any actions defined in the script.
Recommendations for creating a post-processing script:
-
Wrap the script in a
CDATA
element. -
Use the following JavaScript objects and functions (expand to view).Copy code
Function
Object
Error
decodeURI
decodeURIComponent
encodeURI
encodeURIComponent
escape
isNaN
unescape
NaN
isFinite
parseFloat
parseInt
Infinity
undefined
EvalError
RangeError
ReferenceError
SyntaxError
TypeError
URIError
Array
String
Boolean
Number
Date
Math
JSON
RegExp
For examples of scripts, see Post-processing script examples.
For details about component processes, see Create and design component processes.
Create a post-processing script
To add a post-processing script, you need a Web UI role with the Settings permission. Administrators have this permission by default.
For details about Web UI roles, see Web UI roles and UI security.
To create a post-processing script:
-
In Deployment Automation, go to Administration > Automation.
-
Select the Post Processing Scripts tab.
-
Click Create.
-
Specify the post-processing script details:
Field Description Name Enter the name of the script. The name must match the one you specified in the process step's properties. Script Body Enter or paste your script.
Tip: To view information about the properties and variables available for user-defined scripts, hover over the field name.
- Click Save.
Note: Alternatively, you can create a post-processing script in the process designer when you set the properties for a plugin step.
Post-processing script examples
Use these examples of post-processing scripts to create your own scripts.
To specify the Status property with the value of Success, use the following script:
properties.put("Status","Success");
In this example, the post-processing script evaluates the exit codes specified in the script, and triggers actions based on exit code values.
In the post-processing script, include the scanner object:
-
Use scanner.register() to register the strings "Exception" and "Process finished with value = " with a regular expression engine, and then run commands if those strings are found.
-
Use scanner.scan() to scan each line of the step's output log after the strings are registered.
properties.put("Status", "Success");
// Evaluate the built-in exitCode property, which indicates the exit code of the script called by the step.
// Typically, if the value of the exitCode property is not a zero, the step failed.
if (properties.get("exitCode") == 0) {
properties.put("Status", "Success");
} else {
// properties.put("Status", "Failure");
// Use the scanner object to search the log for the string "Exception" (not case-sensitive).
// The first argument is a regular expression.
//
// The second argument is an inline function, and it is invoked once for every line in the log output that matches the pattern.
// The "number" variable contains the line number where the match was found, and the "fullLine" variable is the full text of the line.
scanner.register("(?i)Exception", function(number, fullLine) {
properties.put("LineString", fullLine);
properties.put("Line", new java.lang.String(number));
properties.put("Status", "Failure");
});
// You can register multiple searches with the scanner. Add another search to look for a string to set as an output property.
scanner.register("Process finished with value = ", function(number, fullLine) {
var value = fullLine.replace("Process finished with value = ", "");
properties.put("ProcessValue", value);
});
scanner.scan();
}
This example demonstrates how to pass a property from an earlier step to any of the later steps in the same process.
Assume you have a process with two steps, Prepare Environment (earlier step) and Perform Deployment (later step). Perform Deployment is a Shell step.
To pass a property:
-
Add the following post-processing script to the Prepare Environment step to create two output properties, Status and isDone:
Copy codeif (properties.get("exitCode") == 0) {
properties.put("Status", "Success");
properties.put("isDone", "true");
} else {
properties.put("Status", "Failure");
properties.put("isDone", "false");
} -
Set the contents of the Perform Deployment step to enable the step to access the property from the Prepare Environment step:
Copy codeecho Custom properties of the Prepare Environment step:
echo "Prepare Environment/isDone = ${p:Prepare Environment/isDone}"
The Perform Deployment step can also use the properties of the Prepare Environment step in its post-processing script.
For example, to specify the property isDone of the Prepare Environment step in the property PrepareEnvironmentDone for the Perform Deployment step, use the following post-processing script:
if (properties.get("exitCode") == 0) {
properties.put("Status", "Success");
} else {
properties.put("Status", "Failure");
}
properties.put("PrepareEnvironmentDone", "${p:Prepare Environment/isDone}");
This example demonstrates how to pass a value from an earlier step to any of the later steps in the same process.
Assume you have a process with two steps, Prepare Environment (earlier step) and Perform Deployment (later step). Prepare Environment is a Shell step.
To pass a value:
-
In the Prepare Environment step, write the needed value to the step's output log, where the post-processing script can access the value.
For example, use an
echo
command to add a record to the log:Copy codeecho "Preparing environment..."
echo "Status of environment preparation = SUCCESS" -
In the post-processing script for the Prepare Environment step, use the scanner object to scan the log for the string "Status of environment preparation = ". After that, assign the value to an output property, for example, PrepareEnvironmentStatus.
Copy codeif (properties.get("exitCode") == 0) {
properties.put("Status", "Success");
} else {
properties.put("Status", "Failure");
}
scanner.register("Status of environment preparation = ", function(lineNumber, line) {
var value = line.replace("Status of environment preparation = ", "");
properties.put("PrepareEnvironmentStatus", value);
});
scanner.scan(); -
To pass the value to a later step, reference the output property PrepareEnvironmentStatus in that step.
For example, pass the value to the Perform Deployment step:
Copy codeecho "Status of environment preparation is ${p:Prepare Environment/PrepareEnvironmentStatus}"
See also: