Skip to content

Commit bba74c7

Browse files
authored
doc: add multiple source howto (#2126)
* doc: add multiple source howto * fix typo
1 parent 03d79c7 commit bba74c7

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

content/en/docs/core/source.adoc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The "source" stage retrieves information from a third "resource" like a file, or
2727

2828
== Example
2929

30+
=== Transform source output
31+
3032
.updatecli.yaml
3133
```
3234
sources:
@@ -48,3 +50,58 @@ sources:
4850

4951
In this example we're looking for the latest release tag from https://github.com/jenkinsci/jenkins which is 'jenkins-2.75'.
5052
Unfortunately, it contains the prefix "jenkins" which is not required for later stages, so we remove 'jenkins-' so the output of the source becomes "jenkins/jenkins:2.275-jdk" which is a valid docker image name This can now be used in the later stages.
53+
54+
=== Combine multiple sources
55+
56+
In Updatecli, sources define values (like version numbers) to use in your update logic.
57+
58+
You can combine outputs from multiple sources in a target, a condition, or even another source by using Go templating, like this:
59+
60+
```
61+
sources:
62+
appVersion:
63+
kind: githubrelease
64+
spec:
65+
owner: myorg
66+
repository: myapp
67+
68+
chartVersion:
69+
kind: helmchart
70+
spec:
71+
name: mychart
72+
73+
targets:
74+
updateChart:
75+
name: "Update Helm chart with app and chart versions"
76+
kind: file
77+
disablesourceinput: true
78+
spec:
79+
file: charts/myapp/Chart.yaml
80+
matchpattern: "version: .*"
81+
replacepattern: 'version: {{ source "chartVersion" }}'
82+
```
83+
84+
Now, if you wanted to use both versions in one target, for example in a file or title, you can do something like this:
85+
86+
```
87+
replacepattern: 'appVersion: {{ source "appVersion" }}, chartVersion: {{ source "chartVersion" }}'
88+
```
89+
90+
Here are a few important concepts to understand:
91+
By default any condition or target inherites a source output, so we want to disable that behavior by setting `disablesourceinput: true`.
92+
93+
Combining multiple sources output is useful when:
94+
95+
Another resource needs information from more than one source, like updating multiple versions in the same file or message.
96+
97+
You want to compose a more informative or specific change, like:
98+
99+
```
100+
image: 'myapp:{{ source "appVersion" }}-{{ source "buildNumber" }}'
101+
```
102+
103+
PR titles like:
104+
105+
```
106+
"chore: 'bump app to {{ source "appVersion" }} and chart to {{ source "chartVersion" }}"'
107+
```

0 commit comments

Comments
 (0)