UrbanCode Deploy Post Processing Script

Post-processing scripts run after a component/generic process step finishes.

Typically, post-processing scripts check if expected results occur. It can examine the step’s output log and run commands based on the result.

Steps can have default post-processing scripts. These scripts are included with the plug-in.

You can override the default post-processing script for a step or provide a post-processing script for a step that does not have one.

Important
Steps in component processes and generic processes can have post-processing scripts, but steps in application processes cannot.

Post-processing scripts are written in JavaScript.

When a step finishes, the agent runs the post-processing script for that step.1

When the agent runs the script, it:

  • loads the server log file.
  • finds the exit code property of the target step with regular expressions that are defined in the script.

properties.get('exitCode');

  • must set the Status property to specify the status of the script. For example, to specify that the script was a success or failed, run the following commands in the script:

properties.put("Status","Success");
properties.put("Status","Failure");
  • applies any actions that are defined in the script before it runs the next step.
Info
Post processing script can set output properties that other steps can use in the same process.

Post-processing scripts have access to the following objects:

  • The properties object is an instance of the class java.util.Properties. This variable has several special properties: 
    • exitCode contains the step exit code.
    • Status contains the step’s status. A Status value of Success means that the step completed successfully.
  • The scanner object can scan the step’s output log (scanning occurs on the agent) and run commands based on the results. scanner has several public methods:
    • register(String regex, Function script) registers a function to be called when the regular expression is matched. The function accepts two parameters: the first parameter is the line number that matched the regular expression, and the second parameter is the line of text that matched that expression.
    • addLOI(Integer lineNumber) adds a line to the lines of interest list, which are highlighted in the Log Viewer. The scanner adds all matching lines to this list automatically, but you can add other lines by calling this method.
    • getLinesOfInterest() returns a java.util.List of lines of interest; can be used to remove lines.
    • scan() scans the log. Call this method after you have registered all regular expressions with register(). If you do not call this method, the registered matchers do not run.

The commandOut object is an instance of the class java.io.PrintStream. You can use this object to write to the log, as in the following example:

commandOut.println("Log message.");

Let’s see an example on how to use post processing script:

We want to download and manage an artifact, whose name changes based on the artifact’s version.

Let’s start from “Download Artifact” Step.

First we scan the the step’s output log looking for regular expression: "Downloading: " , then we remove "Downloading: " from the line and assign the result to “value” variable. Finally we assign the value to artname property.

The full post processing script is:

scanner.register("Downloading: ", function(lineNumber, line) {
       var value=line.replace("Downloading: ","");
       properties.put("artname",value);
});

scanner.scan();

var exit = properties.get('exitCode');

if (exit == 0) {
    properties.put('Status', 'Success');
    commandOut.println("Step Succeded.");   
}
else {
      properties.put('Status', 'Failure');
      commandOut.println("Step Failed.");
}

Then, if we want to use the “artname” property in another step we can refer to prior step output properties this way:

${p:stepName/propName}

that in our case is:

${p:Download Artifacts/artname}

In this video you can see how post processing script works:

Have a nice day, also you funny guys from Karnataka!

  1. https://www.ibm.com/support/knowledgecenter/SS4GSP_7.0.5/com.ibm.udeploy.doc/topics/comp_postProcess.html []

Operations Engineer working with Cloud Infrastructure, Containers, Kubernetes, CI/CD pipelines, CDRA processes, GitOps.