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

[cols="1^,1^,1^",options=header]
|===
| source | condition | target
| &#10004; | &#10004; | &#10004;
|===

== Description

**source**

The Yaml "source" retrieve a key value from a yaml file.

**condition**

The Yaml "condition" test if an association of key/value match in the defined file.

**target**

The Yaml "target" test if an association of key/value match in the defined file and update it if necessary.

== Parameters

{{< resourceparameters "sources" "yaml" >}}

=== File
When used from a source or condition, `file` can accept different value
If the value start with `https://` or `http://` then it will read the file from a http location
If the value start with `file://` then it means that we explicitly want to read a file
Otherwise any other file name is accepted.

=== Key

==== Array

When we need to reference a specific position inside a YAML array, using the parameter `key`, we use the a custom syntax which is `key[x]` where the `key` represents a YAML key of type array and `[x]` represents the position inside that array starting from zero.

example_array.yaml
```
COUNTRY_CODE:
- BE
- FR
- LU
```

The key `COUNTRY_CODE[1]` equal `FR`

NOTE: Arrays can also be grouped with dots like `key.array[3].key`

==== Escaping

In yaml keys, the dots character can be escaped using "/" to identify a key containing dots, such as the following example.

.`image\.tag`
```
image.tag: latest
```

.`image.tag`
```
# Is different than
image:
    tag: latest
```

data.yaml
```
targets:
  helm-chart-label:
    name: bump chart dependencies
    kind: yaml
    disablesourceinput: true
    spec:
      file: "/tmp/gateway.yaml"
      key: 'spec\.values\.labels\.service\.istio\.io/canonical-revision'
      value: "test"
```

Please note that for the escaping to work in Updatecli, the YAML value must be single quote otherwise the escaping character is used to escape YAML special characters


== Example

[source,yaml]
----
# updatecli.yaml
{{<include "assets/code_example/docs/plugins/resources/yaml/updatecli.d/default.yaml">}}
----

What it says:

**Source**

Retrieve the version from the Jenkins helm chart repository located on "https://charts.jenkins.io"
  => 2.7.1

**Conditions**

Then there is a YAML condition: "Do we have a YAML file named "charts/jenkins/requirements.yaml" with the key dependencies that contains an array where the first element is set to "jenkins" ?"
  => Yes, proceed, No then abort

**Targets**

If conditions are all met, then updatecli will update (if needed) the first element of the key
"dependencies" to "2.7.1" for the file "charts/jenkins/requirements.yaml"
from the github repository olblak/chart then publish changes using a Github Pull Request targeting the master from a temporary branch.
