Yaml

kind: yaml

sourceconditiontarget

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

NameTypeDescriptionRequired
filestringSpecifies the YAML file
keystringSpecifies the YAML key
keyonlyboolean[condition] allow checking for only the existence of a key (not its value)
valuestringSpecifies the YAML value

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 explicitely want to read a file Otherwise any other file name is accepted.

Key

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

Example

# updatecli.yaml
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:
  isPrometheuseHelmChartVersionAvailable:
    name: "Test if the prometheus helm chart is available"
    kind: helmChart
    spec:
      url: https://prometheus-community.github.io/helm-charts
      name: prometheus
      versionFilter:
        kind: semver
        pattern: "11.16.5"

  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 it tests two conditions.

  1. Test a helmchart condition, "Is the prometheus helm chart version "11.16.5" is available from https://prometheus-community.github.io/helm-charts? ⇒ Yes, proceed, No then abort

  2. - Test 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.

Top