Postp extension

postp is a powerful CloudBees CD feature (postprocessor) you can use to monitor step output in real-time and take action. Frequently, the action is to extract information from step output, store it in the CloudBees CD database, and set properties for reporting. In addition, postp can be used to execute functionality depending on whether or not a pattern is found. Postp, an essential part of the CloudBees CD toolbox, provides fast feedback to users about job step status.

Postp matchers are written in Perl. Postp extensions are either loaded from a file located on the CloudBees CD server or from a stored property.

This tutorial demonstrates how to construct a simple custom postp matcher to extend postp capabilities, and loads the postp extension from a property.

To view an example procedure for this tutorial , go to the automation platform UI > Projects > EC-Tutorials- <version> , and click the procedure name.

An explanation of what you see:

  • This procedure implements a single step, "get directory listing", that retrieves a directory listing using a simple Perl script. Perl is used for the example to ensure the same output no matter which operating system is used for this tutorial. Understanding the Perl code used to generate the tutorial listing is not required for this tutorial.

  • A property was created. This procedure has a postp extension attached in a property named matcher and contains the following Perl code:

    use ElectricCommander;
    push (@::gMatchers,
       {
          id => "fileCountMatcher",pattern => q{(\d+ File\(s\))},
          action => q{setProperty("summary", "Matcher $matcher->{id} found the following output\n\n$1");}
       }
    );

The postp matcher has an identifier ("id"), a regular expression ("pattern") that matches text and an "action" to be performed when text matching the regular expression is found. In this case, the regular expression "id" is fileCountMatcher, and an example of the output being matched is " 2 File(s) ". When the pattern is matched, the action to perform is to set the summary property to the text matched by the regular expression.

The custom postp matcher is loaded using the following command in the Postprocessor field when creating the step: postp –loadProperty /myProcedure/matcher

Click on the step name to go to the Edit Step page to see how this step was created—note the text in the Command box and the Postprocessor field. Click Run to run this sample procedure and see the resulting job on the Job Details page.

See the Status column. The number of files in the file system root where the workspace is located is displayed.

postpext

Implementation

To try using postp functionality in your own project:

  • Edit an existing procedure or create a new one with a "matcher" as a property. For your practice example, you can "copy and paste" the matcher example provided in this tutorial (above).

  • Create a new Command step for this procedure—filling in the Postprocessor field on the New Steps page. Again, for practice, you can use the postp string provide above in this tutorial.

When you run your new procedure, you will see results similar to those you saw after running the tutorial example procedure.

Any changes you make within this tutorial will not be saved when you upgrade CloudBees CD.