This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/docs/guides/1228-handling-outputs.md
Marcos Lilljedahl 37db71104c docs: Add guide to showcase handling outputs
Add a guide which highlights how to handle action's outputs by writing
them to the client filesystem and using CUE's integrations to marshal
them as JSON.

Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
2022-04-13 13:42:42 -05:00

1.8 KiB

slug displayed_sidebar
/1226/handling-outputs 0.2

Handling action outputs

It's most likely that upon executing a Dagger action, you'll find in the situation of having to parse some outputs. In Dagger 0.1 (pre-Europa), inputs and outputs had to be specifically defined; starting Dagger 0.2 (Europa) we introduced a brand new API which removed this capability temporarily until we come up with the right UX to bring this back. Until the API is ready, you can follow this guide which shows different temporary alternatives of parsing dagger outputs.

Writing outputs to the filesystem

As showcased in the interacting with the client docs, Dagger already has the ability to write into the client filesystem through the client API. Using this capability we can then output any value into our local filesystem for further automation.

Here's a simple example of a plain text output:

After performing dagger do test, a new file named output.txt will be present in the current working directory with the output of the bash.#Run action.

Marshalling multiple outputs

The above example works well for simple outputs, but most of the time some actions like Netlify's can output mutiple values. In this case, Netlify's action is returning the deployment url, deployUrl and logsUrl. On this case, we can leverage on CUE's default integrations and marshal all the values into a single json or yaml file.

Here's an example on how to marshal multiple output values: