Git Branch
kind: gitbranch
On this page
source | condition | target |
---|---|---|
✔ | ✔ | ✔ |
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
Name | Type | Description | Required |
---|---|---|---|
branch | string | branch specifies the branch name compatible:
| |
password | string | “password” specifies the password when using the HTTP protocol
| |
path | string | path contains the git repository path | |
sourcebranch | string | “url” specifies the git url to use for fetching Git Tags.
| |
url | string | “sourcebranch” defines the branch name used as a source to create the new Git branch. compatible:
remark:
| |
username | string | “username” specifies the username when using the HTTP protocol
| |
versionfilter | object | VersionFilter provides parameters to specify version pattern and its type like regex, semver, or just latest. compatible:
| |
kind | string | specifies the version kind such as semver, regex, or latest | |
pattern | string | specifies the version pattern according the version kind | |
strict | boolean | strict 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.
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
.
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"