Git Branch

kind: gitbranch

sourceconditiontarget

source

The Git Branch "source" retrieves the latest git branch matching a pattern.

condition

The Git branch "condition" tests if git branch matching a pattern exist.

target

The Git branch "target" ensures a git branch matching a pattern exist otherwise it creates it.

Parameter

The git branch resource is a resource designed to be used with the scmID

NameTypeDescriptionRequired
branchstring

branch specifies the branch name

compatible:

  • source
  • condition
  • target
passwordstring

“password” specifies the password when using the HTTP protocol

compatible:
  * source
  * condition
  * target
pathstringpath contains the git repository path
sourcebranchstring

“url” specifies the git url to use for fetching Git Tags.

compatible:
  * source
  * condition
  * target

example:
  * git@github.com:updatecli/updatecli.git
  * https://github.com/updatecli/updatecli.git

remarks:
	when using the ssh protocol, the user must have the right to clone the repository
	based on its local ssh configuration
urlstring

“sourcebranch” defines the branch name used as a source to create the new Git branch.

compatible:

  • target

remark:

  • sourcebranch is required when the scmid is not defined.
usernamestring

“username” specifies the username when using the HTTP protocol

compatible
  * source
  * condition
  * target
versionfilterobject

VersionFilter provides parameters to specify version pattern and its type like regex, semver, or just latest.

compatible:

  • source
  • condition
  • target
    kindstringspecifies the version kind such as semver, regex, or latest
    patternstringspecifies the version pattern according the version kind
    strictbooleanstrict enforce strict versioning rule. Only used for semantic versioning at this time

Example

# updatecli.yaml
scms:
  default:
    kind: github
    spec:
      branch: master
      email: me@olblak.com
      owner: updatecli-test
      repository: nocode
      token: '{{ requiredEnv "GITHUB_TOKEN" }}'
      user: updatecli
      username: '{{ requiredEnv "GITHUB_ACTOR" }}'
    disabled: false

sources:
  default:
    name: Get Latest branch using semantic versioning
    kind: gitbranch
    scmid: default
    spec:
      versionfilter:
        kind: semver

conditions:
  default:
    name: Test that branch returned from source exists
    kind: gitbranch
    scmid: default
    sourceid: default
  master:
    name: Test that branch master exists
    kind: gitbranch
    scmid: default
    disablesourceinput: true
    spec:
      branch: master

targets:
  default:
    name: Ensure the branch return from source if it doesn't exist
    kind: gitbranch
    scmid: default
    disablesourceinput: true
    spec:
      branch: v1
  alreadyexist:
    name: Ensure the branch "master" exists
    kind: gitbranch
    scmid: default
    spec:
      branch: master

VersionFilter

versionFilter allows to specify the kind of version retrieved from a resource and its version pattern. Default value is "latest" as we want to retrieve the newest version from a resource.

latest

If kind is set to latest then no need to specify the patter as we gonna retrieve the newest version from the resource.

Example
sources:
  kubectl:
    kind: githubRelease
    spec:
      owner: "kubernetes"
      repository: "kubectl"
      token: "{{ requiredEnv .github.token }}"
      username: "john"
      versionFilter:
        kind: latest
    transformers:
      - trimPrefix: "kubernetes-"

Return the latest Github release and remove "kubernetes-" from it.

regex

If versionFilter.kind is set to regex then we can use versionFilter.pattern to specify a regular expression to return the newest version returned from a resource matching the regex If no versionFilter.pattern is provided then it uses '.*' which return the newest version

sources:
  kubectl:
    kind: githubRelease
    spec:
      owner: "kubernetes"
      repository: "kubectl"
      token: "{{ requiredEnv .github.token }}"
      username: "john"
      versionFilter:
        kind: regex
        pattern: "kubernetes-1.(\d*).(\d*)$"
    transformers:
      - trimPrefix: "kubernetes-"

⇒ Return the newest kubectl version matching pattern "kubernetes-1.(\d*).(\d*)$" and remove "kubernetes-" from it

semver

If versionFilter.kind is set to semver then we can use versionFilter.pattern to specify version pattern as explained here. In the process we also sort. If no versionFilter.pattern is provided then it fallback to '*' which return the newest version. If a version doesn’t respect semantic versioning, then it’s not the value is just ignored.

Remark

In the process we drop any characters not respecting semantic version like in this version "v1.0.0", we drop the "v" but we can added it back using transformers.

example
  jenkins-wiki-exporter:
    kind: githubRelease
    spec:
      owner: "jenkins-infra"
      repository: "jenkins-wiki-exporter"
      token: "{{ requiredEnv .github.token }}"
      username: "john"
      versionFilter:
        kind: semver
        pattern: "~1.10"

⇒ Return the version "v1.10.3"

Top