Multiline Regex Capture
Multiline Regex Capture
This log filter creates a Rundeck data variable and fills the contents of that variable via a regular expression.
Provide a regex match with a pattern, and the filter will match against every line in the log returns for that pattern. Every matching value for that pattern will be added to a variable in the data context ( $data.key ) for later steps in the job.
Like the Key Value Data log filter, one capture group is required. Optionally, two capture groups can be provided. If two are provided, then the first match will be the key for each line, while the second will be added as a value. Otherwise, for one capture group, the user must provide a key in the “Name Data” field.
Usage
This log filter has four fields to configure:
- Pattern - required. The value is a regular expression that must contain either one or two capture groups, as described above.
- Name Data - optional. If only one capture group is provided in the Pattern field, then Name Data must have a value. If filled, then this field will be the key for any created key-value pairs.
- Hide Output - checkbox. If true, log output for the attached job step will be hidden.
- Log Data - checkbox. If true, the captured data will be passed along in the job log.
Tips
When multiple values match, then $data.key will equal all of the matched values, separated by a newline.
Capture Multiple Values
If the Capture multiple values
option is checked, each line is scanned separately to match the regex, capturing multiple key/value pairs. This means that it is possible to capture a different key/value set for each matched line.
Then, in case of the output log is:
hello 1
world 2
goodbye 3
Configuring the log filter with the regex (\w+)\s(\d+)
will produce three key/value set:
$data.hello = 1
$data.world = 2
$data.goodbye = 3
And, also, if log filter settings has one group regex, i.e. (\w+\s\d+)
, the user must provide a key in the “Name Data” field and the values should be all lines matched. So, for the same output as above, it would produce the key/value pair:
$data.my_match =
hello 1
world 2
goodbye 3