Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import org.jenkinsci.plugins.pipeline.modeldefinition.shaded.com.fasterxml.jackson.databind.JsonNode
import org.jenkinsci.plugins.pipeline.modeldefinition.shaded.com.github.fge.jsonschema.main.JsonSchema
import org.jenkinsci.plugins.pipeline.modeldefinition.shaded.com.github.fge.jsonschema.main.JsonSchemaFactory
import org.jenkinsci.plugins.pipeline.modeldefinition.shaded.com.github.fge.jsonschema.util.JsonLoader
@NonCPS
def validate(payload) {
def jsonString = libraryResource 'org/mozilla/fxtest/pulse-schema.json'
JsonNode json = JsonLoader.fromString(jsonString)
def factory = JsonSchemaFactory.byDefault()
schema = factory.getJsonSchema(json);
def mapper = new ObjectMapper()
def instance = mapper.readTree(JsonOutput.toJson(payload))
result = schema.validate(instance).isSuccess ? 'Success' : 'Failure'
echo "$result validating Pulse payload against schema."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.