# Transformer<no value>

// <!-- Required for asciidoctor -->
:toc:
// Set toclevels to be at least your hugo [markup.tableOfContents.endLevel] config key
:toclevels: 4

== Description

The "transformers" parameter can be used by any stage definition as a "source", "condition", or "target".
A "transformers" object contains a list of transformers. Each kind of transformer rules applies a string manipulation like adding or removing characters.

**source**

Source returns information modified by a list of transformers.

**condition**

A condition receives information from the source then modifies that value using transformers before using it in the resource.

**target**

A target receives information from the source then modifies that value with the transformers rule before using the resource.

== Parameters

|===
| Name | Default |Description
| replacer |-| Replace a string with another one, more link:#_replacer[here]
| replacers |-| A list of Replacer
| addprefix |-| Add prefix to the value
| addsuffix |-| Add suffix to the value
| trimprefix |-| Remove prefix to the value
| trimsuffix |-| Remove suffix to the value
| find |-| Search for a string value using regular expression and then return its value exist
| findsubmatch |-| Search for a substring using a regular expression and return its content, more link:#_FindSubMatch[here]
| semverinc| - | Bump semantic version, accept a comma separated list of ["major","minor","patch"]
| quote | false | Add quotes around the value
| unquote | false | Remove quotes around the value
|===


=== Replacer

A replacer rule modifies the information by replacing the "from" value by the "to" value.

[cols="1,1,1,4",options=header]
|===
| Name | Required | Default |Description
| from | &#10004;|-| "from" value defines the string that will be replaced
| to | &#10004;|-| "to" value defines the string that we want to have
|===


=== FindSubMatch

A `findsubmatch` rule captures the desired information by applying `pattern` as a regexp and using `captureindex` value as the index for the capture to return (defaults to 0 which returns all submatches).

[cols="1,1,1,4",options=header]
|===
| Name | Required | Default |Description
| pattern | &#10004;|-| `pattern` value defines the regular expression to apply
| captureindex |-|-| `captureindex` value defines the index of the capture to return. Note that the default value `0` returns all submatches, and individual submatch indexes start at `1`.
|===


== Example

The `findsubmatch` below returns the submatch captured with `(.*?)`:

.updatecli.yaml
```
sources:
  default:
    name: "Get latest jenkins weekly version"
    kind: jenkins
    transformers:
      - addprefix: "alpha-"
      - addsuffix: "-jdk11"
      - trimsuffix: "-jdk11"
      - trimprefix: "alpha-"
      - replacer:
          from: "-jdk11"
          to: "-jdk15"
      - replacers:
          - from: "-jdk15"
            to: "-jdk17"
      - findsubmatch:
          pattern: '"(.*?):(.*)'
          captureindex: 1
      - findsubmatch:
          pattern: '(\d*).(\d*).(\d*)'
          capturepattern: "major: \\3, minor: \\2, patch: \\1"
      - semverinc: "major,minor"
      - find: "2.234.(.*)$"
    spec:
      release: weekly
targets:
  targetID:
    name: "Update file file"
    kind: file
    spec:
      file: TODO
```
