Step Post-Processing: <post-processing> Element

When a plugin step's <command> element finishes processing, the step's mandatory <post-processing> element is executed. The <post-processing> element optionally sets the step's output properties and 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 Deployment Automation editor. Although not required, Serena recommends 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 on the agent and take actions depending on the results. The scanner variable may use the following public methods:

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 also use post-processing scripts to set output properties that can then be used in other steps in the same process. This enables you to design complex workflows. Reference prior step output properties this way:

${p:stepName/propName}