Creating post-processing scripts

Post-processing scripts are used in job steps to determine the success or failure of a step. Success is determined by the exit code and log of the step.

A typical post-processing script might check for a nonzero exit code, or look for some expected string in the step output.
  1. On the IBM® UrbanCode™ Build dashboard, click System, then click Post-Processing in the Script Library area.
  2. Click Create New Script.
  3. On the New Post-Processing Script window, type a name for the script in the Name field.
  4. Enter the script in the Script box.
    The script must be written in JavaScript.™ The step output properties are in a java.util.Properties variable named properties. The exitCode property contains the exit code of the process. The Status property contains the final status. Any Status value other than Success results in the step failing. The scanner variable can be used to scan the output log of the step. The scanner variable has several public methods:
    • register(String regex, function call) registers a new function to be called whenever the regular expression is matched.
    • addLOI(Integer lineNumber) adds a specific line to the lines of interest list. The lines are highlighted in the LogViewer after the process finishes. This is implicitly called anytime scan() matches a line.
    • getLinesOfInterest() returns a java.util.List list that contains the lines of interest. This method can be used to remove lines if necessary.

    After all regular expressions are registered, use scan.scan() to scan the log.

  5. Click Save.
commandOut.println("This is a test command output line! This can be used as a means of logging messages!");
var prop1Value = "";
scanner.register("^prop1=", function(lineNumber, line) {
  commandOut.println("Inside callback for line of interest: " + line);
  prop1Value = line.substr(line.indexOf('=') + 1, line.length - line.indexOf('='));
  properties.put("buildlife/prop1", prop1Value);
});
scanner.scan();
commandOut.println("Exit code is: " + properties.get("exitCode"));
commandOut.println("Value for property 1 is: " + prop1Value);
properties.put("Status", "Success");

The example includes a couple of statements with the commandOut command. You can use commandOut command to print messages that can be used for tracing flow and debugging.

In regards to setting Status, while there is nothing wrong with explicitly setting a Failure status, there is no need to. Lack of a Status property with a value of Success is equivalent to Failure. Basically, anything other than Success is considered Failure.

To review or edit an existing script, select the script. For information about scripting, see the Build Scripting page: click Help > Tools > Scripting API.