Skip to content

Commit

Permalink
fix(pipeline_template): Plan serialization & empty string rendering (#…
Browse files Browse the repository at this point in the history
…1581)

* fix(pipeline_template): Render empty strings as null

* fix(pipeline_template): Fix method signature now that spring pays attention
  • Loading branch information
robzienert authored Aug 29, 2017
1 parent 633fb6c commit 34c449b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
package com.netflix.spinnaker.orca.pipelinetemplate.v1schema.render;

import com.netflix.spinnaker.orca.pipelinetemplate.exceptions.TemplateRenderException;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.composer.ComposerException;
import org.yaml.snakeyaml.parser.ParserException;

import java.util.Arrays;
import java.util.List;

public class YamlRenderedValueConverter implements RenderedValueConverter {

private static final List<String> YAML_KEYWORDS = Arrays.asList("yes", "no", "on", "off");
Expand All @@ -44,7 +45,10 @@ public Object convertRenderedValue(String renderedValue) {

try {
Object converted = yaml.load(renderedValue);
return (converted == null || converted instanceof String) ? renderedValue : converted;
if (converted == null || converted instanceof String) {
return "".equals(converted) || "".equals(renderedValue) ? null : renderedValue;
}
return converted;
} catch (ComposerException ce) {
throw new TemplateRenderException("template produced invalid yaml", ce);
} catch (ParserException pe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class JinjaRendererSpec extends Specification {
def result = subject.renderGraph(template, context)

then:
expectedType.isAssignableFrom(result.getClass())
if (result != null) {
expectedType.isAssignableFrom(result.getClass())
}
result == expectedResult

where:
Expand Down Expand Up @@ -84,6 +86,7 @@ class JinjaRendererSpec extends Specification {
'#stage("First Wait")["status"].toString() == "SUCCESS"' || String | '#stage("First Wait")["status"].toString() == "SUCCESS"'
'${ #stage("First Wait")["status"].toString() == "SUCCESS" }' || String | '${ #stage("First Wait")["status"].toString() == "SUCCESS" }'
'${ parameters.CONFIG_FOLDER ?: \'\' }' || String | '${ parameters.CONFIG_FOLDER ?: \'\' }'
'' || String | null
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class OperationsController {
WebhookService webhookService

@RequestMapping(value = "/orchestrate", method = RequestMethod.POST)
Map<String, String> orchestrate(@RequestBody Map pipeline, HttpServletResponse response) {
Map<String, Object> orchestrate(@RequestBody Map pipeline, HttpServletResponse response) {
parsePipelineTrigger(executionRepository, buildService, pipeline)
Map trigger = pipeline.trigger

Expand Down

0 comments on commit 34c449b

Please sign in to comment.