Skip to content
Permalink
Browse files
[FIXED JENKINS-41503] Allow null values in JSON
Also required changing org.json -> Jackson conversion to go through a
string rather than use a mapper due to the mapper not liking nulls at
all.
  • Loading branch information
abayer committed Feb 22, 2017
1 parent c40dd71 commit 6e518e32c311d5f80458a1911cbbea6b4da87783
@@ -10,7 +10,8 @@
"type": [
"number",
"string",
"boolean"
"boolean",
"null"
]
}
},
@@ -24,6 +24,7 @@
package org.jenkinsci.plugins.pipeline.modeldefinition.parser

import com.cloudbees.groovy.cps.NonCPS
import com.github.fge.jsonschema.util.JsonLoader
import org.jenkinsci.plugins.pipeline.modeldefinition.shaded.com.fasterxml.jackson.databind.JsonNode
import org.jenkinsci.plugins.pipeline.modeldefinition.shaded.com.fasterxml.jackson.databind.ObjectMapper
import org.jenkinsci.plugins.pipeline.modeldefinition.shaded.com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule
@@ -87,10 +88,7 @@ public class Converter {
* @return The converted {@link JsonNode}
*/
public static JsonNode jacksonJSONFromJSONObject(JSONObject input) {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JsonOrgModule());

return mapper.valueToTree(input);
return JsonLoader.fromString(input.toString())
}

public static JsonTree jsonTreeFromJSONObject(JSONObject input) {
@@ -139,7 +139,8 @@ public void setUp() throws Exception {
"whenEnvFalse",
"parallelPipelineWithSpaceInBranch",
"parallelPipelineQuoteEscaping",
"nestedTreeSteps"
"nestedTreeSteps",
"jsonSchemaNull"
);

public static Iterable<Object[]> configsWithErrors() {
@@ -0,0 +1,49 @@
{"pipeline": {
"stages": [ {
"name": "foo",
"branches": [ {
"name": "default",
"steps": [
{
"name": "sh",
"arguments": [ {
"key": "script",
"value": {
"isLiteral": true,
"value": "cat /usr/local/apache2/conf/extra/httpd-userdir.conf"
}
}]
},
{
"name": "sh",
"arguments": [ {
"key": "script",
"value": {
"isLiteral": true,
"value": "echo \"The answer is 42\""
}
}]
}
]
}]
}],
"agent": {
"type": "docker",
"arguments": [
{
"key": "image",
"value": {
"isLiteral": true,
"value": "httpd:2.4.12"
}
},
{
"key": "args",
"value": {
"isLiteral": true,
"value": null
}
}
]
}
}}
@@ -0,0 +1,43 @@
/*
* The MIT License
*
* Copyright (c) 2017, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pipeline {
agent {
docker {
image "httpd:2.4.12"
args null
}
}
stages {
stage("foo") {
steps {
sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
sh 'echo "The answer is 42"'
}
}
}
}



0 comments on commit 6e518e3

Please sign in to comment.