The post-processing element

When a plug-in step's <command> element finishes processing, the step's mandatory <post-processing> element runs.

The <post-processing> element sets the step's output properties (step name/property name, see IBM UrbanCode Deploy 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 they define the step in the IBM® UrbanCode Deploy editor, see Post-processing scripts.

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 that the step completed successfully.

Another available variable, scanner, can scan the step's output log (scanning occurs on the agent) and run commands based on the results. scanner has several public methods:

The post-processing script can examine the step's output log, and run commands based on the result. In the following code fragment, scanner.register() registers the strings error at line and the value is with a regular expression engine, then runs commands if those strings are found. After all strings are registered, it calls scanner.scan() on the step's output log line by line.

     properties.put("Status", "Success");

     //
     // Evaluate the built-in exitCode property, which indicates the exit code
     // of the script called by the plug-in step. Typically, if the value of
     // the exitCode property is non-zero, the plug-in step failed.
     //
     if (properties.get("exitCode") != 0) {
          properties.put("Status", "Failure");
     }
     else {

          //
          // Register a scanner to search for the text "error at line" in the log.
          // The first argument is a regular expression.
          //
          // The second argument, an inline function, is invoked once for
          // every line in the log output that matches the pattern. The "lineNumber"
          // variable contains the line number where the match occurred, and the
          // "line" variable is the full text of the line.
          //
          scanner.register("(?i)ERROR at line",  function(lineNumber, line) {

              //
              // In this case, we build up an "Error" property which
              // contains the text of all errors that are found. We find every
              // line starting with "error at line" and add it to this list.
              //
              var errors = properties.get("Error");
              if (errors == null) {
                  errors = new java.util.ArrayList();
              }
              errors.add(line);


              //
              // If a line starting with "error at line" is found, the step has
              // failed, so we set the special "Status" property to "Failure",
              // indicating to the UrbanCode Deploy server that the step should
              // be marked as a failure.
              //
              properties.put("Status", "Failure");
          });
         
          //
          // Multiple searches can be registered with the scanner. We add a
          // second search to look for some interesting text to set as an output
          // property.
          //
          // For example, if there is a line "The value is BLUE", then we end up
          // with an output property, "Value", with a value of "BLUE".
          //
          scanner.register("The value is", function(lineNumber, line) {
              var value = line.replace("The value is ", "");
              properties.put("Value", value);
          });
         
          scanner.scan();


          //
          // Convert the collected list of error strings into a single string and
          // set that as an output property.
          //
          var errors = properties.get("Error");
          if (errors == null) {
              errors = new java.util.ArrayList();
          }
          properties.put("Error", errors.toString());
     }
You can use a post-processing script 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}

Feedback