You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/plugins/resource/file.adoc
+77Lines changed: 77 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,7 @@ It retrieves the content of the file at the location `file` and use it as the so
65
65
* `content`
66
66
* `forcecreate`
67
67
* `replacepattern`
68
+
* `template`
68
69
69
70
=== Filtering File Source Content
70
71
@@ -233,6 +234,7 @@ or fails the pipeline (and never run the pipeline's targets).
233
234
234
235
* `forcecreate`
235
236
* `replacepattern`
237
+
* `template`
236
238
237
239
=== Condition Input Value
238
240
@@ -427,10 +429,15 @@ The "Input Value" is the string to write to the specified file.
427
429
* You can also specify a custom content with the `spec.content` attribute instead of using the input source value.
428
430
Using the `spec.content` is useful when you need to templatize with the source input value (see example below).
429
431
432
+
* Alternatively, you can define a Go template file path with the `spec.template` attribute to render dynamic content based on the source value.
433
+
The template is rendered using all https://masterminds.github.io/sprig/[Sprig template functions], with the source value accessible as `.source` in the template context.
434
+
430
435
* Finally, you can define a https://pkg.go.dev/regexp[Golang regexp] in the attribute `spec.ReplacePattern`,
431
436
if and only if you also specified a `spec.matchpattern` (see <<Restricting File Content Update>> and <<Target Examples>> for more details).
432
437
** Regexp's capturing group are supported (this is the recommended use case)
433
438
439
+
⚠️ The `spec.template` attribute is mutually exclusive with `spec.content`, `spec.matchpattern`, `spec.replacepattern`, and `spec.line`.
440
+
434
441
=== Restricting File Content Update
435
442
436
443
You may restrict which part of the specified file to be updated with the input value with the following options:
@@ -558,6 +565,70 @@ updateCopyrightYear
558
565
--
559
566
560
567
568
+
* The following target uses a Go template file to generate dynamic content based on the source value.
569
+
The template has access to all https://masterminds.github.io/sprig/[Sprig functions] and the source value via `.source`:
570
+
+
571
+
[source,yaml]
572
+
.updateCli.yaml:
573
+
--
574
+
# ..
575
+
sources:
576
+
getLatestVersion:
577
+
kind: shell
578
+
spec:
579
+
command: "echo \"1.25.1\""
580
+
targets:
581
+
useTemplate:
582
+
kind: file
583
+
sourceid: getLatestVersion # Source Value is "1.25.1"
The shell 🐚 command "/bin/sh /tmp/updatecli/bin/ab7e342dff922f8ba849dbf7d0c4ac2adc5855b83fe02401b781e7267f7233c6.sh" ran successfully with the following output:
610
+
----
611
+
1.25.1
612
+
----
613
+
✔ shell command executed successfully
614
+
615
+
target: useTemplate
616
+
-------------------
617
+
618
+
Creating a new file at "version-info.txt"
619
+
"version-info.txt" updated with content "Application Version Information\n================================\n\nCurrent Version: 1.25.1\nUpdated: 2026-01-21\nRelease Notes: https://example.com/releases/1.25.1\n"
0 commit comments