Target
Description
The "target" stage applies the value retrieved by a source to a "resource", such as a file in a Git repository. It is the only stage allowed to modify something, and it runs only once every condition succeeded.
A target reports one of three outcomes:
success - the resource already holds the expected value, nothing to do
attention - the resource is out of date. In
diffmode Updatecli only reports the change, inapplymode it writes itfailure - the target could not be evaluated
When a target is attached to an scmid, applying a change also commits it and pushes it to the configured branch,
which in turn triggers the actions depending on that scm.
Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| dependson | array | “dependson” allows to specify the order of execution of resources. It accepts a list of rules like “(resourceType#)resourceId(:booleanOperator)”. The resourceType is optional and can be one of “condition”, “source” or “target” By default the resourceType is the current resource type The resourceId is the name of the resource to depend on The booleanOperator is optional and can be “AND” or “OR” examples: dependson: * condition#myCondition:and * source#mySource remarks:
| |
| dependsonchange | boolean | ||
| deprecatedconditionids | array | ||
| disableconditions | boolean | ||
| disablesourceinput | boolean | ||
| kind | string | kind specifies the targets resource kind | |
| name | string | name specifies the resource name | |
| scmid | string | scmid specifies the scm configuration key associated to the current resource | |
| sourceid | string | ||
| spec | object | spec specifies parameters for a specific targets kind | |
| transformers | array | transformers defines how the default input value need to be transformed | |
| addprefix | string | AddPrefix adds a prefix to the transformer input value | |
| addsuffix | string | AddSuffix adds a suffix to the transformer input value | |
| find | string | Find searches for a specific value if it exists and return false if it doesn’t | |
| findsubmatch | object | Find searches for a specific value if it exists then return the value using regular expression | [pattern] |
| jsonmatch | object | [key] | |
| quote | boolean | Quote add quote around the value | |
| replacer | object | Replacer specifies what value needs to be changed and how | [from to] |
| replacers | array | Replacers specifies a list of replacer instruction | |
| semverinc | string | SemvVerInc specifies a comma separated list semantic versioning component that needs to be upgraded. | |
| trimprefix | string | TrimPrefix removes a prefix to the transformer input value | |
| trimsuffix | string | TrimSuffix removes the suffix from the transformer input value | |
| unquote | boolean | Unquote remove quotes around the value |
Source input
By default, a target consumes the output of a source:
when the manifest defines exactly one source, that source is used automatically
when the manifest defines more than one source,
sourceidbecomes mandatorysetting
disablesourceinput: trueruns the target without a source value. The target spec must then carry its own value, typically built with{{ source "id" }}templating
Note | disablesourceinput: true also hides source information, such as the changelog, from the actions that follow. A github/pullrequest action will not be able to render the changelog of a target whose source input is disabled. |
Conditions
A target waits for all the conditions of the manifest and is skipped as soon as one of them does not succeed.
To narrow that down, set disableconditions: true and declare the relevant conditions explicitly:
targets:
default:
kind: yaml
disableconditions: true
dependson:
- condition#dockerImageExists
spec:
file: values.yaml
key: $.image.tagChaining targets with dependsonchange
dependson only requires the depended-on resource to succeed.
Adding dependsonchange: true narrows it further: the target runs only if the targets it depends on
actually changed something.
This is how you express "only bump the changelog if the version file was really updated":
targets:
version:
name: Update the version file
kind: file
spec:
file: VERSION
changelog:
name: Add a changelog entry
kind: file
# Only run when the "version" target modified something
dependson:
- version
dependsonchange: true
spec:
file: CHANGELOG.mdNote | Inside dependson, an entry without a <category># prefix refers to a resource of the same category, so version above means target#version. |
Examples
Update a YAML key from a GitHub release
name: "deps: bump Updatecli version"
sources:
updatecli:
name: Get the latest Updatecli version
kind: githubrelease
spec:
owner: updatecli
repository: updatecli
token: '{{ requiredEnv "GITHUB_TOKEN" }}'
versionfilter:
kind: semver
transformers:
- trimprefix: "v"
targets:
chart:
name: 'deps: bump Updatecli version to {{ source "updatecli" }}'
kind: yaml
sourceid: updatecli
scmid: default
spec:
file: charts/updatecli/values.yaml
key: $.image.tagUpdate several files with the same value
A target kind that accepts a files key updates every listed file in one go, and reports a single change.
targets:
dockerfiles:
name: 'deps: bump Golang version to {{ source "golang" }}'
kind: dockerfile
scmid: default
spec:
files:
- Dockerfile
- test/Dockerfile
instruction:
keyword: ARG
matcher: GOLANG_VERSIONGo Further
To know more about the value a target receives source
To know more about gating targets condition
To know more about execution order manifest order
To know more about what happens after a change action