@@ -17,6 +17,7 @@ For example:
17
17
18
18
- [ Syntax] ( #syntax )
19
19
- [ Resource types] ( #resource-types )
20
+ - [ Using Resources] ( #using-resources )
20
21
21
22
## Syntax
22
23
@@ -41,6 +42,161 @@ following fields:
41
42
[ kubernetes-overview] :
42
43
https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields
43
44
45
+ ## Using Resources
46
+
47
+ Resources can be used in [ Tasks] ( ./tasks.md ) and [ Conditions] ( ./conditions.md#resources ) .
48
+
49
+ Input resources, like source code (git) or artifacts, are dumped at path
50
+ ` /workspace/task_resource_name ` within a mounted
51
+ [ volume] ( https://kubernetes.io/docs/concepts/storage/volumes/ ) and is available
52
+ to all [ ` steps ` ] ( #steps ) of your ` Task ` . The path that the resources are mounted
53
+ at can be [ overridden with the ` targetPath ` field] ( ./resources.md#controlling-where-resources-are-mounted ) .
54
+ Steps can use the ` path ` [ variable substitution] ( #variable-substitution ) key to refer to the local path to the mounted resource.
55
+
56
+ ### Variable substitution
57
+
58
+ ` Task ` and ` Condition ` specs can refer resource params as well as pre-defined variables such as
59
+ ` path ` using the variable substitution syntax below where ` <name> ` is the Resource Name and ` <key> `
60
+ is a one of the resource's ` params ` :
61
+
62
+
63
+ #### In Task Spec:
64
+ For an input resource in a ` Task ` spec:
65
+ ``` shell
66
+ $( inputs.resources.< name> .< key> )
67
+ ```
68
+
69
+ Or for an output resource:
70
+
71
+ ``` shell
72
+ $( outputs.resources.< name> .< key> )
73
+ ```
74
+
75
+ #### In Condition Spec:
76
+ Input resources can be accessed by:
77
+
78
+ ``` shell
79
+ $( resources.< name> .< key> )
80
+ ```
81
+
82
+ #### Accessing local path to resource
83
+
84
+ The ` path ` key is pre-defined and refers to the local path to a resource on the mounted volume
85
+ ``` shell
86
+ $( inputs.resouces.< name> .path)
87
+ ```
88
+
89
+ _ The deprecated syntax ` ${} ` , e.g. ` ${inputs.params.<name>} ` will be supported
90
+ until [ #1170 ] ( https://github.com/tektoncd/pipeline/issues/1170 ) ._
91
+
92
+ ### Controlling where resources are mounted
93
+
94
+ The optional field ` targetPath ` can be used to initialize a resource in specific
95
+ directory. If ` targetPath ` is set then resource will be initialized under
96
+ ` /workspace/targetPath ` . If ` targetPath ` is not specified then resource will be
97
+ initialized under ` /workspace ` . Following example demonstrates how git input
98
+ repository could be initialized in ` $GOPATH ` to run tests:
99
+
100
+ ``` yaml
101
+ apiVersion : tekton.dev/v1alpha1
102
+ kind : Task
103
+ metadata :
104
+ name : task-with-input
105
+ namespace : default
106
+ spec :
107
+ inputs :
108
+ resources :
109
+ - name : workspace
110
+ type : git
111
+ targetPath : go/src/github.com/tektoncd/pipeline
112
+ steps :
113
+ - name : unit-tests
114
+ image : golang
115
+ command : ["go"]
116
+ args :
117
+ - " test"
118
+ - " ./..."
119
+ workingDir : " /workspace/go/src/github.com/tektoncd/pipeline"
120
+ env :
121
+ - name : GOPATH
122
+ value : /workspace/go
123
+ ` ` `
124
+
125
+ ### Overriding where resources are copied from
126
+
127
+ When specifying input and output ` PipelineResources`, you can optionally specify
128
+ ` paths` for each resource. `paths` will be used by `TaskRun` as the resource's
129
+ new source paths i.e., copy the resource from specified list of paths. `TaskRun`
130
+ expects the folder and contents to be already present in specified paths.
131
+ ` paths` feature could be used to provide extra files or altered version of
132
+ existing resource before execution of steps.
133
+
134
+ Output resource includes name and reference to pipeline resource and optionally
135
+ ` paths` . `paths` will be used by `TaskRun` as the resource's new destination
136
+ paths i.e., copy the resource entirely to specified paths. `TaskRun` will be
137
+ responsible for creating required directories and copying contents over. `paths`
138
+ feature could be used to inspect the results of taskrun after execution of
139
+ steps.
140
+
141
+ ` paths` feature for input and output resource is heavily used to pass same
142
+ version of resources across tasks in context of pipelinerun.
143
+
144
+ In the following example, task and taskrun are defined with input resource,
145
+ output resource and step which builds war artifact. After execution of
146
+ taskrun(`volume-taskrun`), `custom` volume will have entire resource
147
+ ` java-git-resource` (including the war artifact) copied to the destination path
148
+ ` /custom/workspace/` .
149
+
150
+ ` ` ` yaml
151
+ apiVersion: tekton.dev/v1alpha1
152
+ kind: Task
153
+ metadata:
154
+ name: volume-task
155
+ namespace: default
156
+ spec:
157
+ inputs:
158
+ resources:
159
+ - name: workspace
160
+ type: git
161
+ outputs:
162
+ resources:
163
+ - name: workspace
164
+ steps:
165
+ - name: build-war
166
+ image: objectuser/run-java-jar #https://hub.docker.com/r/objectuser/run-java-jar/
167
+ command: jar
168
+ args: ["-cvf", "projectname.war", "*"]
169
+ volumeMounts:
170
+ - name: custom-volume
171
+ mountPath: /custom
172
+ ` ` `
173
+
174
+ ` ` ` yaml
175
+ apiVersion: tekton.dev/v1alpha1
176
+ kind: TaskRun
177
+ metadata:
178
+ name: volume-taskrun
179
+ namespace: default
180
+ spec:
181
+ taskRef:
182
+ name: volume-task
183
+ inputs:
184
+ resources:
185
+ - name: workspace
186
+ resourceRef:
187
+ name: java-git-resource
188
+ outputs:
189
+ resources:
190
+ - name: workspace
191
+ paths:
192
+ - /custom/workspace/
193
+ resourceRef:
194
+ name: java-git-resource
195
+ volumes:
196
+ - name: custom-volume
197
+ emptyDir: {}
198
+ ` ` `
199
+
44
200
# # Resource Types
45
201
46
202
The following `PipelineResources` are currently supported :
0 commit comments