|
| 1 | +<!-- |
| 2 | +--- |
| 3 | +linkTitle: "Artifacts" |
| 4 | +weight: 201 |
| 5 | +--- |
| 6 | +--> |
| 7 | + |
| 8 | +# Artifacts |
| 9 | + |
| 10 | +- [Overview](#overview) |
| 11 | +- [Artifact Provenance Data](#passing-artifacts-between-steps) |
| 12 | + - [Passing Artifacts between Steps](#passing-artifacts-between-steps) |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## Overview |
| 17 | +> :seedling: **`Artifacts` is an [alpha](additional-configs.md#alpha-features) feature.** |
| 18 | +> The `enable-artifacts` feature flag must be set to `"true"` to read or write artifacts in a step. |
| 19 | +
|
| 20 | +Artifacts provide a way to track the origin of data produced and consumed within your Tekton Tasks. |
| 21 | + |
| 22 | +## Artifact Provenance Data |
| 23 | +Artifacts fall into two categories: |
| 24 | + |
| 25 | + - Inputs: Artifacts downloaded and used by the Step/Task. |
| 26 | + - Outputs: Artifacts created and uploaded by the Step/Task. |
| 27 | +Example Structure: |
| 28 | +```json |
| 29 | +{ |
| 30 | + "inputs":[ |
| 31 | + { |
| 32 | + "name": "<input-category-name>", |
| 33 | + "values": [ |
| 34 | + { |
| 35 | + "uri": "pkg:github/package-url/purl-spec@244fd47e07d1004f0aed9c", |
| 36 | + "digest": { "sha256": "b35caccc..." } |
| 37 | + } |
| 38 | + ] |
| 39 | + } |
| 40 | + ], |
| 41 | + "outputs": [ |
| 42 | + { |
| 43 | + "name": "<output-category-name>", |
| 44 | + "values": [ |
| 45 | + { |
| 46 | + "uri": "pkg:oci/nginx:stable-alpine3.17-slim?repository_url=docker.io/library", |
| 47 | + "digest": { |
| 48 | + "sha256": "df85b9e3...", |
| 49 | + "sha1": "95588b8f..." |
| 50 | + } |
| 51 | + } |
| 52 | + ] |
| 53 | + } |
| 54 | + ] |
| 55 | +} |
| 56 | + |
| 57 | +``` |
| 58 | + |
| 59 | +The content is written by the `Step` to a file `$(step.artifacts.path)`: |
| 60 | + |
| 61 | +```yaml |
| 62 | +apiVersion: tekton.dev/v1 |
| 63 | +kind: TaskRun |
| 64 | +metadata: |
| 65 | + generateName: step-artifacts- |
| 66 | +spec: |
| 67 | + taskSpec: |
| 68 | + description: | |
| 69 | + A simple task that populates artifacts to TaskRun stepState |
| 70 | + steps: |
| 71 | + - name: artifacts-producer |
| 72 | + image: bash:latest |
| 73 | + script: | |
| 74 | + cat > $(step.artifacts.path) << EOF |
| 75 | + { |
| 76 | + "inputs":[ |
| 77 | + { |
| 78 | + "name":"source", |
| 79 | + "values":[ |
| 80 | + { |
| 81 | + "uri":"pkg:github/package-url/purl-spec@244fd47e07d1004f0aed9c", |
| 82 | + "digest":{ |
| 83 | + "sha256":"b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0" |
| 84 | + } |
| 85 | + } |
| 86 | + ] |
| 87 | + } |
| 88 | + ], |
| 89 | + "outputs":[ |
| 90 | + { |
| 91 | + "name":"image", |
| 92 | + "values":[ |
| 93 | + { |
| 94 | + "uri":"pkg:oci/nginx:stable-alpine3.17-slim?repository_url=docker.io/library", |
| 95 | + "digest":{ |
| 96 | + "sha256":"df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48", |
| 97 | + "sha1":"95588b8f34c31eb7d62c92aaa4e6506639b06ef2" |
| 98 | + } |
| 99 | + } |
| 100 | + ] |
| 101 | + } |
| 102 | + ] |
| 103 | + } |
| 104 | + EOF |
| 105 | +``` |
| 106 | +
|
| 107 | +It is recommended to use [purl format](https://github.com/package-url/purl-spec/blob/master/PURL-SPECIFICATION.rst) for artifacts uri as shown in the example. |
| 108 | +
|
| 109 | +### Passing Artifacts between Steps |
| 110 | +You can pass artifacts from one step to the next using: |
| 111 | +
|
| 112 | +- Specific Artifact: `$(steps.<step-name>.inputs.<artifact-category-name>)` or `$(steps.<step-name>.outputs.<artifact-category-name>)` |
| 113 | +- Default (First) Artifact: `$(steps.<step-name>.inputs)` or `$(steps.<step-name>.outputs)` (if <artifact-category-name> is omitted) |
| 114 | + |
| 115 | +The example below shows how to access the previous' step artifacts from another step in the same task |
| 116 | + |
| 117 | +```yaml |
| 118 | +apiVersion: tekton.dev/v1 |
| 119 | +kind: TaskRun |
| 120 | +metadata: |
| 121 | + generateName: step-artifacts- |
| 122 | +spec: |
| 123 | + taskSpec: |
| 124 | + description: | |
| 125 | + A simple task that populates artifacts to TaskRun stepState |
| 126 | + steps: |
| 127 | + - name: artifacts-producer |
| 128 | + image: bash:latest |
| 129 | + script: | |
| 130 | + # the script is for creating the output artifacts |
| 131 | + cat > $(step.artifacts.path) << EOF |
| 132 | + { |
| 133 | + "inputs":[ |
| 134 | + { |
| 135 | + "name":"source", |
| 136 | + "values":[ |
| 137 | + { |
| 138 | + "uri":"pkg:github/package-url/purl-spec@244fd47e07d1004f0aed9c", |
| 139 | + "digest":{ |
| 140 | + "sha256":"b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0" |
| 141 | + } |
| 142 | + } |
| 143 | + ] |
| 144 | + } |
| 145 | + ], |
| 146 | + "outputs":[ |
| 147 | + { |
| 148 | + "name":"image", |
| 149 | + "values":[ |
| 150 | + { |
| 151 | + "uri":"pkg:oci/nginx:stable-alpine3.17-slim?repository_url=docker.io/library", |
| 152 | + "digest":{ |
| 153 | + "sha256":"df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48", |
| 154 | + "sha1":"95588b8f34c31eb7d62c92aaa4e6506639b06ef2" |
| 155 | + } |
| 156 | + } |
| 157 | + ] |
| 158 | + } |
| 159 | + ] |
| 160 | + } |
| 161 | + EOF |
| 162 | + - name: artifacts-consumer |
| 163 | + image: bash:latest |
| 164 | + script: | |
| 165 | + echo $(steps.artifacts-producer.outputs) |
| 166 | +``` |
| 167 | + |
| 168 | + |
| 169 | +The resolved value of `$(steps.<step-name>.outputs.<artifact-category-name>)` or `$(steps.<step-name>.outputs)` is the values of an artifact. For this example, |
| 170 | +`$(steps.artifacts-producer.outputs)` is resolved to |
| 171 | +```json |
| 172 | +[ |
| 173 | + { |
| 174 | + "uri":"pkg:oci/nginx:stable-alpine3.17-slim?repository_url=docker.io/library", |
| 175 | + "digest":{ |
| 176 | + "sha256":"df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48", |
| 177 | + "sha1":"95588b8f34c31eb7d62c92aaa4e6506639b06ef2" |
| 178 | + } |
| 179 | + } |
| 180 | +] |
| 181 | +``` |
| 182 | + |
| 183 | + |
| 184 | +Upon resolution and execution of the `TaskRun`, the `Status` will look something like: |
| 185 | +```yaml |
| 186 | +"steps": [ |
| 187 | + { |
| 188 | + "container": "step-artifacts-producer", |
| 189 | + "imageID": "docker.io/library/bash@sha256:5353512b79d2963e92a2b97d9cb52df72d32f94661aa825fcfa0aede73304743", |
| 190 | + "inputs": [ |
| 191 | + { |
| 192 | + "name": "source", |
| 193 | + "values": [ |
| 194 | + { |
| 195 | + "digest": { |
| 196 | + "sha256": "b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0" |
| 197 | + }, |
| 198 | + "uri":"pkg:github/package-url/purl-spec@244fd47e07d1004f0aed9c", |
| 199 | + } |
| 200 | + ] |
| 201 | + } |
| 202 | + ], |
| 203 | + "name": "artifacts-producer", |
| 204 | + "outputs": [ |
| 205 | + { |
| 206 | + "name": "image", |
| 207 | + "values": [ |
| 208 | + { |
| 209 | + "digest": { |
| 210 | + "sha1": "95588b8f34c31eb7d62c92aaa4e6506639b06ef2", |
| 211 | + "sha256": "df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48" |
| 212 | + }, |
| 213 | + "uri":"pkg:oci/nginx:stable-alpine3.17-slim?repository_url=docker.io/library", |
| 214 | + } |
| 215 | + ] |
| 216 | + } |
| 217 | + ], |
| 218 | + "terminated": { |
| 219 | + "containerID": "containerd://010f02d103d1db48531327a1fe09797c87c1d50b6a216892319b3af93e0f56e7", |
| 220 | + "exitCode": 0, |
| 221 | + "finishedAt": "2024-03-18T17:05:06Z", |
| 222 | + "message": "...", |
| 223 | + "reason": "Completed", |
| 224 | + "startedAt": "2024-03-18T17:05:06Z" |
| 225 | + }, |
| 226 | + "terminationReason": "Completed" |
| 227 | + }, |
| 228 | + { |
| 229 | + "container": "step-artifacts-consumer", |
| 230 | + "imageID": "docker.io/library/bash@sha256:5353512b79d2963e92a2b97d9cb52df72d32f94661aa825fcfa0aede73304743", |
| 231 | + "name": "artifacts-consumer", |
| 232 | + "terminated": { |
| 233 | + "containerID": "containerd://42428aa7e5a507eba924239f213d185dd4bc0882b6f217a79e6792f7fec3586e", |
| 234 | + "exitCode": 0, |
| 235 | + "finishedAt": "2024-03-18T17:05:06Z", |
| 236 | + "reason": "Completed", |
| 237 | + "startedAt": "2024-03-18T17:05:06Z" |
| 238 | + }, |
| 239 | + "terminationReason": "Completed" |
| 240 | + } |
| 241 | + ], |
| 242 | +
|
| 243 | +``` |
0 commit comments