class PlatformValidator extends Object
Validates the contents of a platforms file and provides quick access to supported platforms.
To run this example, clone Jervis and execute ./gradlew console to bring up a Groovy Console with the classpath set up.
Please note, if you are writing Job DSL plugin groovy scripts you should not use the relative file paths to access files in the repository where your DSL scripts reside. Instead, use the readFileFromWorkspace method provided by the Job DSL plugin in Jenkins.
import net.gleske.jervis.lang.PlatformValidator
def platforms = new PlatformValidator()
platforms.loadYamlFile('resources/platforms.yaml')
println 'Does the file validate? ' + platforms.validate()
//List supported platforms and operating systems
platforms.platforms['supported_platforms'].sort { k, v -> k }.each { platform, os ->
println "Platform '${platform}' includes operating systems:"
os.sort { k, v -> k }.each { o, s ->
println " ${o} (Supported languages: ${s['language'].sort().join(', ')})"
}
}
null
| Type Params | Return Type | Name and description |
|---|---|---|
|
Map |
getPlatforms(Boolean unstable = false) |
|
void |
loadYamlFile(String file, Boolean unstable = false)Load the YAML of a platforms file and parse it. |
|
void |
loadYamlString(String yaml, Boolean unstable = false)Parse the YAML which is the contents of a platforms file. |
|
Boolean |
validate()Validates the platforms file. |
|
Boolean |
validate(Boolean unstable)Validates the platforms file. |
|
Boolean |
validate_asBool()Executes the validate() function but always returns a Boolean instead of throwing an exception upon failed validation. |
Load the YAML of a platforms file and parse it. This should be the first function called after class instantiation. Alternately, loadYamlString() can be called instead. It populates platforms.
file - A String which is a path to a platforms file.unstable - Load unstable platforms instead of stable.Parse the YAML which is the contents of a platforms file. It populates platforms. This is required in order to use the readFileFromWorkspace method from the Jenkins Job DSL Plugin.
yaml - A String containing the contents of a platforms file.unstable - Load unstable platforms instead of stable.Validates the platforms file.
Validates the platforms file.
@return - true if the platforms file validates. If the platforms file fails validation then it will throw a PlatformValidationException.Executes the validate() function but always returns a Boolean instead of throwing an exception upon failed validation.