0

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:

  • some text DIFF some text
  • some text NO_DIFF some text
  • any text, most likely error message

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?

Aleksandr
  • 1
  • 2

1 Answers1

0

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.

Busy Box
  • 51
  • 5
  • Thank you for answer, in my case how could I check whether result substring contains values like "DIFF" or "NO_DIFF" to switch by them, approach as doesn't work: var foo = line.substring(line.lastIndexOf(':') + 1).trim(); if (foo.includes("DIFF") && !foo.includes("NO_DIFF")) { properties.put("Lorem", foo); } else if (foo.includes("NO_DIFF")) { properties.put("Lorem", foo); } – Aleksandr Apr 18 '18 at 11:58