@@ -23,6 +23,7 @@ const (
23
23
VarKey = "var"
24
24
IteratorKey = "iterator" // reserved for transient one-off values, set/unset when applying values to template
25
25
26
+ StateKey = "state"
26
27
OutputKey = "output"
27
28
MetadataKey = "metadata"
28
29
ChildrenKey = "children"
@@ -140,6 +141,21 @@ func (v *Values) UnsetError(stepName string) {
140
141
v .unsetStepData (stepName , ErrorKey )
141
142
}
142
143
144
+ // GetState returns the state of a step
145
+ func (v * Values ) GetState (stepName string ) interface {} {
146
+ return v .getStepData (stepName , StateKey )
147
+ }
148
+
149
+ // SetState stores the state of a step
150
+ func (v * Values ) SetState (stepName string , value interface {}) {
151
+ v .setStepData (stepName , StateKey , value )
152
+ }
153
+
154
+ // UnsetState empties the state of a step
155
+ func (v * Values ) UnsetState (stepName string ) {
156
+ v .unsetStepData (stepName , StateKey )
157
+ }
158
+
143
159
func (v * Values ) getStepData (stepName , field string ) interface {} {
144
160
stepmap := v .m [StepKey ].(map [string ]interface {})
145
161
if stepmap [stepName ] == nil {
@@ -232,6 +248,9 @@ func (v *Values) Apply(templateStr string, item interface{}, stepName string) ([
232
248
233
249
v .SetError (utask .This , v .GetError (stepName ))
234
250
defer v .UnsetError (utask .This )
251
+
252
+ v .SetState (utask .This , v .GetState (stepName ))
253
+ defer v .UnsetState (utask .This )
235
254
}
236
255
237
256
err = tmpl .Execute (b , v .m )
0 commit comments