Skip to content

Commit

Permalink
kind/feat: surface artifacts through termination message
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzzzzzzz committed Mar 20, 2024
1 parent c8dbe66 commit d7b8ab4
Show file tree
Hide file tree
Showing 27 changed files with 2,011 additions and 4 deletions.
175 changes: 175 additions & 0 deletions docs/artifacts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<!--
---
linkTitle: "Artifacts"
weight: 201
---
-->

# Artifacts

- [Overview](#overview)
- [Artifact Provenance Data](#passing-artifacts-between-steps)
- [Passing Artifacts between Steps](#passing-artifacts-between-steps)



## Overview
> :seedling: **`Artifacts` is an [alpha](additional-configs.md#alpha-features) feature.**
> The `enable-artifacts` feature flag must be set to `"true"` to read or write artifacts in a step.
Artifacts provide a way to track the origin of data produced and consumed within your Tekton Tasks.

## Artifact Provenance Data
Artifacts fall into two categories:

- Inputs: Artifacts downloaded and used by a Task.
- Outputs: Artifacts created and uploaded by a Task.
Example Structure:
```json
{
"inputs":[
{
"name": "source code", // Category name
"values": [
{
"uri": "git:jjjsss",
"digest": { "sha256": "b35caccc..." }
}
]
}
],
"outputs": [
{
"name": "build-result", // Category name
"values": [
{
"uri": "pkg:balba",
"digest": {
"sha256": "df85b9e3...",
"sha1": "95588b8f..."
}
}
]
}
]
}
```

### Passing Artifacts between Steps
You can pass artifacts from one step to the next using:

- Specific Artifact: $(steps.<step-name>.inputs.<artifact-category-name>) or $(steps.<step-name>.outputs.<artifact-category-name>)
- Default (First) Artifact: $(steps.<step-name>.inputs) or $(steps.<step-name>.outputs) (if <artifact-category-name> is omitted)

The example below shows how you could pass step artifacts from a step into following steps,

```yaml
apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
generateName: step-artifacts-
spec:
taskSpec:
description: |
A simple task that populates artifacts to TaskRun stepState
steps:
- name: artifacts-producer
image: bash:latest
script: |
cat > $(step.artifacts.path) << EOF
{
"inputs":[
{
"name":"input-artifacts",
"values":[
{
"uri":"git:jjjsss",
"digest":{
"sha256":"b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0"
}
}
]
}
],
"outputs":[
{
"name":"build-result",
"values":[
{
"uri":"pkg:balba",
"digest":{
"sha256":"df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48",
"sha1":"95588b8f34c31eb7d62c92aaa4e6506639b06ef2"
}
}
]
}
]
}
EOF
- name: artifacts-consumer
image: bash:latest
script: |
echo $(steps.artifacts-producer.outputs)
```
Upon resolution and execution of the `TaskRun`, the `Status` will look something like:
```yaml
"steps": [
{
"container": "step-artifacts-producer",
"imageID": "docker.io/library/bash@sha256:5353512b79d2963e92a2b97d9cb52df72d32f94661aa825fcfa0aede73304743",
"inputs": [
{
"name": "input-artifacts",
"values": [
{
"digest": {
"sha256": "b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0"
},
"uri": "git:jjjsss"
}
]
}
],
"name": "artifacts-producer",
"outputs": [
{
"name": "build-result",
"values": [
{
"digest": {
"sha1": "95588b8f34c31eb7d62c92aaa4e6506639b06ef2",
"sha256": "df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48"
},
"uri": "pkg:balba"
}
]
}
],
"terminated": {
"containerID": "containerd://010f02d103d1db48531327a1fe09797c87c1d50b6a216892319b3af93e0f56e7",
"exitCode": 0,
"finishedAt": "2024-03-18T17:05:06Z",
"message": "[{\"key\":\"/tekton/run/0/status/artifacts/provenance.json\",\"value\":\"{\\n \\\"inputs\\\":[\\n {\\n \\\"name\\\":\\\"input-artifacts\\\",\\n \\\"values\\\":[\\n {\\n \\\"uri\\\":\\\"git:jjjsss\\\",\\n \\\"digest\\\":{\\n \\\"sha256\\\":\\\"b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0\\\"\\n }\\n }\\n ]\\n }\\n ],\\n \\\"outputs\\\":[\\n {\\n \\\"name\\\":\\\"build-result\\\",\\n \\\"values\\\":[\\n {\\n \\\"uri\\\":\\\"pkg:balba\\\",\\n \\\"digest\\\":{\\n \\\"sha256\\\":\\\"df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48\\\",\\n \\\"sha1\\\":\\\"95588b8f34c31eb7d62c92aaa4e6506639b06ef2\\\"\\n }\\n }\\n ]\\n }\\n ]\\n}\\n\",\"type\":5}]",
"reason": "Completed",
"startedAt": "2024-03-18T17:05:06Z"
},
"terminationReason": "Completed"
},
{
"container": "step-artifacts-consumer",
"imageID": "docker.io/library/bash@sha256:5353512b79d2963e92a2b97d9cb52df72d32f94661aa825fcfa0aede73304743",
"name": "artifacts-consumer",
"terminated": {
"containerID": "containerd://42428aa7e5a507eba924239f213d185dd4bc0882b6f217a79e6792f7fec3586e",
"exitCode": 0,
"finishedAt": "2024-03-18T17:05:06Z",
"reason": "Completed",
"startedAt": "2024-03-18T17:05:06Z"
},
"terminationReason": "Completed"
}
],
```
80 changes: 78 additions & 2 deletions docs/pipeline-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ TaskRunStatus
<h3 id="tekton.dev/v1.Artifact">Artifact
</h3>
<p>
(<em>Appears on:</em><a href="#tekton.dev/v1.StepState">StepState</a>)
(<em>Appears on:</em><a href="#tekton.dev/v1.Artifacts">Artifacts</a>, <a href="#tekton.dev/v1.StepState">StepState</a>)
</p>
<div>
<p>TaskRunStepArtifact represents an artifact produced or used by a step within a task run.
Expand Down Expand Up @@ -1390,6 +1390,44 @@ string
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1.Artifacts">Artifacts
</h3>
<div>
</div>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>inputs</code><br/>
<em>
<a href="#tekton.dev/v1.Artifact">
[]Artifact
</a>
</em>
</td>
<td>
</td>
</tr>
<tr>
<td>
<code>outputs</code><br/>
<em>
<a href="#tekton.dev/v1.Artifact">
[]Artifact
</a>
</em>
</td>
<td>
</td>
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1.ChildStatusReference">ChildStatusReference
</h3>
<p>
Expand Down Expand Up @@ -9602,7 +9640,7 @@ TaskRunStatus
<h3 id="tekton.dev/v1beta1.Artifact">Artifact
</h3>
<p>
(<em>Appears on:</em><a href="#tekton.dev/v1beta1.StepState">StepState</a>)
(<em>Appears on:</em><a href="#tekton.dev/v1beta1.Artifacts">Artifacts</a>, <a href="#tekton.dev/v1beta1.StepState">StepState</a>)
</p>
<div>
<p>TaskRunStepArtifact represents an artifact produced or used by a step within a task run.
Expand Down Expand Up @@ -9680,6 +9718,44 @@ string
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1beta1.Artifacts">Artifacts
</h3>
<div>
</div>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>inputs</code><br/>
<em>
<a href="#tekton.dev/v1beta1.Artifact">
[]Artifact
</a>
</em>
</td>
<td>
</td>
</tr>
<tr>
<td>
<code>outputs</code><br/>
<em>
<a href="#tekton.dev/v1beta1.Artifact">
[]Artifact
</a>
</em>
</td>
<td>
</td>
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1beta1.ChildStatusReference">ChildStatusReference
</h3>
<p>
Expand Down
47 changes: 47 additions & 0 deletions examples/v1/taskruns/alpha/produce-consume-artifacts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
generateName: step-artifacts-
spec:
taskSpec:
description: |
A simple task that populates artifacts to TaskRun stepState
steps:
- name: artifacts-producer
image: bash:latest
script: |
cat > $(step.artifacts.path) << EOF
{
"inputs":[
{
"name":"input-artifacts",
"values":[
{
"uri":"git:jjjsss",
"digest":{
"sha256":"b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0"
}
}
]
}
],
"outputs":[
{
"name":"build-result",
"values":[
{
"uri":"pkg:balba",
"digest":{
"sha256":"df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48",
"sha1":"95588b8f34c31eb7d62c92aaa4e6506639b06ef2"
}
}
]
}
]
}
EOF
- name: artifacts-consumer
image: bash:latest
script: |
echo $(steps.artifacts-producer.outputs)
4 changes: 4 additions & 0 deletions hack/ignored-openapi-violations.list
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ API rule violation: list_type_missing,github.com/tektoncd/pipeline/pkg/apis/pipe
API rule violation: list_type_missing,github.com/tektoncd/pipeline/pkg/apis/pipeline/v1,Artifact,Values
API rule violation: list_type_missing,github.com/tektoncd/pipeline/pkg/apis/pipeline/v1,StepState,Inputs
API rule violation: list_type_missing,github.com/tektoncd/pipeline/pkg/apis/pipeline/v1,StepState,Outputs
API rule violation: list_type_missing,github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1,Artifacts,Inputs
API rule violation: list_type_missing,github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1,Artifacts,Outputs
API rule violation: list_type_missing,github.com/tektoncd/pipeline/pkg/apis/pipeline/v1,Artifacts,Inputs
API rule violation: list_type_missing,github.com/tektoncd/pipeline/pkg/apis/pipeline/v1,Artifacts,Outputs
7 changes: 7 additions & 0 deletions internal/artifactref/artifactref.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package artifactref

import "regexp"

const stepArtifactUsagePattern = `\$\(steps\.([^.]+)\.(?:inputs|outputs)(?:\.([^.]+))?\)`

var StepArtifactRegex = regexp.MustCompile(stepArtifactUsagePattern)
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1/artifact_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ type ArtifactValue struct {
// TaskRunStepArtifact represents an artifact produced or used by a step within a task run.
// It directly uses the Artifact type for its structure.
type TaskRunStepArtifact = Artifact

type Artifacts struct {
Inputs []Artifact `json:"inputs,omitempty"`
Outputs []Artifact `json:"outputs,omitempty"`
}
Loading

0 comments on commit d7b8ab4

Please sign in to comment.