XML
| source | condition | target |
|---|---|---|
✔ | ✔ | ✔ |
Description
The xml resource reads and writes a single node in an XML document, located with an XPath query. It is most often used against a Maven pom.xml.
- source
Returns the text content of the node matched by
path.- condition
Checks that the node holds
value, or the source output whenvalueis unset.- target
Writes the value into the node. A document already holding it is reported as up to date and left untouched.
Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| file | string | “file” define the xml file path to interact with. compatible: * source * condition * target remark: * scheme “https://”, “http://”, and “file://” are supported in path for source and condition | |
| path | string | “path” defines the xpath query used for retrieving value from a XML document compatible: * source * condition * target example: * path: “/project/parent/version” * path: “//breakfast_menu/food[0]/name” * path: “//book[@category=‘WEB’]/title” | |
| value | string | “value” is the value associated with a xpath query. compatible: * source * condition * target default: when used from a condition or a target, the default value is set to linked source output |
Both file and path are mandatory. Omitting either aborts the run with wrong spec content, preceded by the specific reason (xml file not specified or xml path undefined).
Important | This resource takes a single file only. There is no files attribute, unlike the yaml, json, toml, csv and hcl resources (update several documents with one target each). |
XPath
path is a standard XPath expression, evaluated against the whole document:
| Expression | Matches |
|---|---|
| An absolute path from the document root. |
| The first |
| Selected by attribute value. |
A path matching nothing makes a source fail, and a condition report a failure rather than error.
Remote files
file accepts https://, http:// and file:// for a source and a condition. A target must write to a local file and refuses a URL:
URL scheme is not supported for XML target: "https://example.com/pom.xml"Example
# updatecli.yaml
name: Show a set of xml resources as a generic example
scms:
ircbot:
kind: git
spec:
url: https://github.com/olblak/ircbot.git
branch: master
sources:
parentVersion:
name: Get parent version from pom.xml
scmid: ircbot
kind: xml
spec:
file: pom.xml
path: "/project/parent/version"
conditions:
parent-version:
name: Test if parent version is set to source output
kind: xml
sourceid: parentVersion
scmid: ircbot
spec:
file: pom.xml
path: "/project/parent/version"
artifactid:
name: Test if parent artifactId is set to jenkins
kind: xml
scmid: ircbot
disablesourceinput: true
spec:
file: pom.xml
path: "/project/parent/artifactId"
value: "jenkins"
targets:
parent-version:
name: Test if parent version is set to source output
kind: xml
sourceid: parentVersion
scmid: ircbot
spec:
file: pom.xml
path: "/project/parent/version"
artifactid:
name: Test if parent artifactId is set to jenkins
kind: xml
scmid: ircbot
disablesourceinput: true
spec:
file: pom.xml
path: "/project/parent/artifactId"
value: "donotjenkins"