Skip to content

Commit

Permalink
fix(core): OutputValues to support arrays and complex objects (#5440)
Browse files Browse the repository at this point in the history
  • Loading branch information
Malaydewangan09 authored Oct 14, 2024
1 parent b5f00e6 commit c667fbf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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

0 comments on commit c667fbf

Please sign in to comment.