When a plug-in step's <command>
element finishes processing, the
step's mandatory <post-processing>
element is executed. The
<post-processing>
element sets the step's output properties (step
name/property name, see uDeploy Properties) and provides error handling. The
<post-processing>
element can contain any valid JavaScript script
(unlike the <command>
element, <post-processing>
scripts must be written in JavaScript). Users can also provide their own scripts when
defining the step in the uDeploy editor, see the section called “Post-Processing Scripts”.
Although not required, it's recommended that scripts be wrapped in a CDATA
element.
You have access to a java.util.Properties
variable called properties
. The properties
variable has several special properties: exitCode
contains the process exit code, and Status
contains the step's status. A Status
value of Success
means the step completed successfully.
Another available variable—scanner
—
can scan the step's output log (scanning occurs on the agent) and take
actions depending on the results. scanner
has several public methods:
-
register(String regex, function call)
registers a function to be called when the regular expression is matched. -
addLOI(Integer lineNumber)
adds a line to the lines of interest list, which are highlighted in the Log Viewer; implicitly called wheneverscanner
matches a line. -
getLinesOfInterest()
returns a java.util.List of lines of interest; can be used to remove lines. -
scan()
scans the log. Use after all regular expressions are registered.
The post-processing script can examine the step's output log, and take actions based
on the result. In the following code fragment, scanner.register()
registers
a string with a regular expression engine, then takes an action if the string is found.
Once all strings are registered, it calls scanner.scan()
on the step's
output log line by line.
<![CDATA[ properties.put("Status", "Success"); if (properties.get("exitCode") != 0) { properties.put("Status", "Failure"); } else { scanner.register("(?i)ERROR at line", function(lineNumber, line) { var errors = properties.get("Error"); if (errors == null) { errors = new java.util.ArrayList(); } errors.add(line); properties.put("Error", errors); properties.put("Status", "Failure"); }); . . . scanner.scan(); var errors = properties.get("Error"); if (errors == null) { errors = new java.util.ArrayList(); } properties.put("Error", errors.toString()); } ]]
You can use a post-processing scripts to set output properties that can be used in other steps in the same process, which enables complex workflows. Reference prior step output properties this way:
${p:stepName/propName}