sourceconditiontarget

✔

✔

✔

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 when value is unset.

target

Writes the value into the node. A document already holding it is reported as up to date and left untouched.

Parameters

NameTypeDescriptionRequired
filestring

“file” defines the path of the xml file to use.

compatible:

  • source
  • condition
  • target

remark:

  • “file” is required.
  • the schemes “https://”, “http://” and “file://” are supported in a source or a condition.

example:

  • file: pom.xml
pathstring

“path” defines the xpath query used to retrieve a value from the xml document.

compatible:

  • source
  • condition
  • target

remark:

  • “path” is required.

example:

  • path: “/project/parent/version”
  • path: “//breakfast_menu/food[0]/name”
  • path: “//book[@category=‘WEB’]/title”
valuestring

“value” defines the value associated with the xpath query.

compatible:

  • condition
  • target

default: the output of the associated source.

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:

ExpressionMatches

/project/parent/version

An absolute path from the document root.

//breakfast_menu/food[0]/name

The first food entry, indexed from zero.

//book[@category='WEB']/title

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"