Aleksandr
Aleksandr

Reputation: 1

urbancode deploy post-script

I want to switch (via "switch.variable") application process into 3 different way, based on results returned of component process. Component process contain shell (bash) script which can return strings as follow:

Then in the same component process I want to process re results of bash script using post-script as follow:

if (properties.get("exitCode") != 0) {
    properties.put('Status', 'Failure');
    properties.remove("switch.variable")
    commandOut.println("Error")
} else {
    properties.put('Status', 'Success');
    scanner.register("any text", function (lineNumber, line) {
        if (line.contains("DIFF")) {
            properties.put("switch.variable", "DIFF")
        } else if (line.contains("NO_DIFF")) {
            properties.put("switch.variable", "NO_DIFF")
        }
        commandOut.println(properties.get("switch.variable"));
    });
    scanner.scan();
}

Could you help me to write proper post-script?

Upvotes: 0

Views: 1596

Answers (1)

Busy Box
Busy Box

Reputation: 51

Consider you have a shell script box named 'Shell' in your component process that looks like:

echo 'some text: DIFF'

For this box you should add a post-processing script like below:

if( properties.get("exitCode") != 0 ){
    properties.put('Status', 'Failure');
}
else {
       properties.put('Status', 'Success');
       var regex = "some text";
       scanner.register(regex, function(lineNumber,line){
       var foo = line.substring(line.lastIndexOf(':')+1).trim();
       // The ':' is the symbol after which the payload value starts.
       properties.put("Lorem", foo );
});
scanner.scan();

Then you put a 'switch' box after your shell script box named 'Shell'. In the property name of that switch, put Shell\Lorem.

From here you can branch your switch cases by drawing arrows with values you want, like DIFF, NO_DIFF, default. The default arrow will cover unexpected cases. Also you may have some another logic for Shell box failure. It will require outgoing arrow with red sign.

Upvotes: 0

Related Questions