Skip to content

Script Artifact Passing

from hera.workflows import Artifact, Steps, Workflow, script


@script(outputs=Artifact(name="hello-art", path="/tmp/hello_world.txt"))
def whalesay():
    with open("/tmp/hello_world.txt", "w") as f:
        f.write("hello world")


@script(inputs=Artifact(name="message", path="/tmp/message"))
def print_message():
    with open("/tmp/message", "r") as f:
        message = f.readline()
    print(message)


with Workflow(generate_name="artifact-passing-", entrypoint="artifact-example") as w:
    with Steps(name="artifact-example") as s:
        whale_step = whalesay(name="generate-artifact")
        print_message(
            name="consume-artifact",
            arguments=whale_step.get_artifact("hello-art").with_name("message"),
        )
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: artifact-passing-
spec:
  entrypoint: artifact-example
  templates:
  - name: artifact-example
    steps:
    - - name: generate-artifact
        template: whalesay
    - - arguments:
          artifacts:
          - from: '{{steps.generate-artifact.outputs.artifacts.hello-art}}'
            name: message
        name: consume-artifact
        template: print-message
  - name: whalesay
    outputs:
      artifacts:
      - name: hello-art
        path: /tmp/hello_world.txt
    script:
      command:
      - python
      image: python:3.8
      source: |-
        import os
        import sys
        sys.path.append(os.getcwd())
        with open('/tmp/hello_world.txt', 'w') as f:
            f.write('hello world')
  - inputs:
      artifacts:
      - name: message
        path: /tmp/message
    name: print-message
    script:
      command:
      - python
      image: python:3.8
      source: |-
        import os
        import sys
        sys.path.append(os.getcwd())
        with open('/tmp/message', 'r') as f:
            message = f.readline()
        print(message)

Comments