Skip to content

Commit

Permalink
feat(EvaluateVariables): Support complex objects in EvaluateVariables…
Browse files Browse the repository at this point in the history
… stage (#3232)
  • Loading branch information
christopherthielen committed Oct 17, 2019
1 parent e1511d5 commit 31e5229
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public EvaluateVariablesStageContext(

public static class Variable {
private String key;
private String value;
private Object value;

@JsonCreator
public Variable(@JsonProperty("key") String key, @JsonProperty("value") String value) {
public Variable(@JsonProperty("key") String key, @JsonProperty("value") Object value) {
this.key = key;
this.value = value;
}
Expand All @@ -63,15 +63,15 @@ public void setKey(String key) {
this.key = key;
}

public void setValue(String value) {
public void setValue(Object value) {
this.value = value;
}

public String getKey() {
return key;
}

public String getValue() {
public Object getValue() {
return value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public TaskResult execute(@Nonnull Stage stage) {
EvaluateVariablesStage.EvaluateVariablesStageContext context =
stage.mapTo(EvaluateVariablesStage.EvaluateVariablesStageContext.class);

Map<String, String> outputs = new HashMap<>();
Map<String, Object> outputs = new HashMap<>();
for (EvaluateVariablesStage.Variable v : context.getVariables()) {
outputs.put(v.getKey(), v.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,39 @@ class EvaluateVariablesTaskSpec extends Specification {
result.outputs.get("myKey1") == "ohWow"
result.outputs.get("myKey2") == "myMy"
}

void "Supports values that are complex objects"() {
setup:
def simpleValue = "A simple string";
def simpleArray = ["string1", "string2", "string3"];
def objectArray = [ [id: "15"], [id: "25"], [id: "45"] ];
def someStuff = [
nestedValue: 'value',
number: 1,
nestedHash: [
nestedNested: 'nestedNestedValue',
nestedArray: [1, 2, 3, 4, 5],
]
]

def stage = stage {
refId = "1"
type = "evaluateVariables"
context["variables"] = [
["key": "simpleValue", "value": simpleValue],
["key": "simpleArray", "value": simpleArray],
["key": "objectArray", "value": objectArray],
["key": "hashMap", "value": someStuff]
]
}

when:
def result = task.execute(stage)

then:
result.outputs.get("simpleValue") == simpleValue
result.outputs.get("simpleArray") == simpleArray
result.outputs.get("objectArray") == objectArray
result.outputs.get("hashMap") == someStuff
}
}

0 comments on commit 31e5229

Please sign in to comment.