Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OutputValues to support arrays and complex objects #5440

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions core/src/main/java/io/kestra/plugin/core/output/OutputValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
You can use this task to return some outputs and pass them to downstream tasks.
It's helpful for parsing and returning values from a task. You can then access these outputs in your downstream tasks
using the expression `{{ outputs.mytask_id.values.my_output_name }}` and you can see them in the Outputs tab.
The values can be strings, numbers, arrays, or any valid JSON object.
"""
)
@Plugin(
Expand All @@ -39,6 +40,11 @@
values:
taskrun_data: "{{ task.id }} > {{ taskrun.startDate }}"
execution_data: "{{ flow.id }} > {{ execution.startDate }}"
number_value: 42
array_value: ["{{ task.id }}", "{{ flow.id }}", "static value"]
nested_object:
key1: "value1"
key2: "{{ execution.id }}"
- id: log_values
type: io.kestra.plugin.core.log.Log
Expand All @@ -51,15 +57,16 @@
)
public class OutputValues extends Task implements RunnableTask<OutputValues.Output> {
@Schema(
title = "The templated strings to render."
title = "The templated strings to render.",
description = "These values can be strings, numbers, arrays, or objects. Templated strings (enclosed in {{ }}) will be rendered using the current context."
)
private HashMap<String, String> values;
private HashMap<String, Object> values;


@Override
public OutputValues.Output run(RunContext runContext) throws Exception {
return OutputValues.Output.builder()
.values(runContext.renderMap(values))
.values(runContext.render(values))
.build();
}

Expand All @@ -69,6 +76,6 @@ public static class Output implements io.kestra.core.models.tasks.Output {
@Schema(
title = "The generated values."
)
private Map<String, String> values;
private Map<String, Object> values;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void output() throws Exception {
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
assertThat(execution.getTaskRunList(), hasSize(1));
TaskRun outputValues = execution.getTaskRunList().getFirst();
Map<String, String> values = (Map<String, String>) outputValues.getOutputs().get("values");
Map<String, Object> values = (Map<String, Object>) outputValues.getOutputs().get("values");
assertThat(values.get("output1"), is("xyz"));
assertThat(values.get("output2"), is("abc"));
}
Expand Down
Loading