Yaml
kind: yaml
On this page
source | condition | target |
---|---|---|
✔ | ✔ | ✔ |
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
Name | Type | Description | Required |
---|---|---|---|
file | string | [source,condition,target] File contains the file path to take in account | |
files | array | [source,condition,target] Files contains the file path(s) to take in account. For 'source': limited to one item | |
indent | integer | [target] Indent defines the yaml indentation for file updated by target of kind yaml. Default to 2 | |
key | string | [source,condition,target] Key is the YAML key to retrieve | |
keyonly | boolean | [condition] allow checking for only the existence of a key (not its value) | |
value | string | [source,condition,target] Value is the YAML value to set. Default value set to source output for condition and target |
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
# updatecli.yaml
name: Example of YAML resources
scms:
default:
kind: github
spec:
user: "my git user"
email: "my git email"
owner: "olblak"
repository: "chart"
token: "{{ requiredEnv .github.token }}"
username: "github username"
branch: "main"
sources:
lastRelease:
kind: helmchart
spec:
url: https://charts.jenkins.io
name: jenkins
conditions:
chartVersion:
name: "jenkinsci/jenkins Helm Chart used"
kind: yaml
scmid: default
spec:
file: "charts/jenkins/requirements.yaml"
key: "dependencies[0].name"
value: "jenkins"
targets:
chartVersion:
name: "jenkinsci/jenkins Helm Chart"
kind: yaml
scmid: default
spec:
file: "charts/jenkins/requirements.yaml"
key: "dependencies[0].version"
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.