-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kind/feat: surface artifacts through termination message
- Loading branch information
1 parent
c8dbe66
commit d7b8ab4
Showing
27 changed files
with
2,011 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
], | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.