class pipelineGenerator extends Object
This class offers helper forunctions for using Jervis in the context of a Jenkins pipeline global shared library.
To run this example, clone Jervis and execute ./gradlew console to bring up a Groovy Console with the classpath set up.
import net.gleske.jervis.lang.lifecycleGenerator import net.gleske.jervis.lang.pipelineGenerator def generator = new lifecycleGenerator() generator.loadLifecyclesString(new File('resources/lifecycles-ubuntu1604-stable.json').text) generator.loadToolchainsString(new File('resources/toolchains-ubuntu1604-stable.json').text) generator.loadYamlString(''' language: groovy env: ["GROOVY_VERSION=1.8.9", "GROOVY_VERSION=2.4.12"] jdk: - openjdk8 - openjdk9 jenkins: stash: - name: artifacts allow_empty: true includes: build/lib/*.jar matrix_axis: env: GROOVY_VERSION=2.4.12 jdk: openjdk8 collect: artifacts: build/lib/*.jar '''.trim()) def pipeline_generator = new pipelineGenerator(generator) pipeline_generator.supported_collections = ['artifacts'] pipeline_generator.getBuildableMatrixAxes().each { axis -> if(pipeline_generator.getStashMap(axis)) { println "stash ${axis} ---> ${pipeline_generator.getStashMap(axis)}" } } println "Buildable matrices: " + pipeline_generator.getBuildableMatrixAxes().size()
Type | Name and description |
---|---|
Map |
collect_settings_defaults This is a Map of default settings for the YAML key jenkins.collect. |
Map |
collect_settings_filesets Some settings defined in collect_settings_defaults support Ant filesets and this Map adds support for those settings. |
Map |
collect_settings_validation This is a Map of validation for settings defined in the YAML key jenkins.collect. |
Map |
stashmap_preprocessor Customize the processing of stashmaps for stash names. |
Set<String> |
supported_collections A set of collections which a global pipeline library might support. |
Constructor and description |
---|
pipelineGenerator
(lifecycleGenerator generator) Instantiates this class with a lifecycleGenerator which is used for helper functions when creating a pipeline job designed to support Jervis. |
Type Params | Return Type | Name and description |
---|---|---|
|
List |
getBuildableMatrixAxes() Returns a list of maps which are buildable matrices in a matrix build. |
|
def |
getPublishable(String item) Get a publishable item from the list of publishable items. |
|
List |
getPublishableItems() Get a list of publishable items which show up in .jervis.yml. |
|
List |
getSecretPairsEnv() Processes secret properties from .jervis.yml into two lists. |
|
Map |
getStashMap(Map matrix_axis = [:]) Returns a list of stashes from Jervis YAML to be stashed either serially or in this matrix axis for matrix builds. |
|
void |
setCollect_settings_defaults(Map m) This method merges Map m with the existing map collect_settings_defaults. |
|
void |
setStashmap_preprocessor(Map m) This filter ensures an admin only sets proper closures for the stashmap_processor. |
This is a Map of default settings for the YAML key jenkins.collect. Key names in this map are similar to the keys in jenkins.collect if specifying default settings for a jenkins.collect item. By a collect item being set with defaults we are stating that the settings should be defined by the user and if not the default value from this map is selected. This allows providing more advanced options to users but allowing sane defaults to be defined if a user chooses not to define more advanced options in YAML.
Some settings defined in collect_settings_defaults support Ant filesets and this Map adds support for those settings.
This is a Map of validation for settings defined in the YAML key jenkins.collect. Sometimes, when specifying plugins validation of values is required. Validation of values can take the form of a list of acceptable regex patterns or a single regex pattern to validate what the user defined. Some settings, an admin may desire, to limit user input if it's a String value. Validation can only be defined for Strings.
Customize the processing of stashmaps for stash names. A stashmap preprocessor can be used to customize how stashing is calculated for custom publishers. For example, this is necessary for publishers. All keys must be a String. All values must be a Closure which takes a single argument that is a Map. The following is an example.
import net.gleske.jervis.lang.lifecycleGenerator import net.gleske.jervis.lang.pipelineGenerator String yaml = ''' language: groovy jenkins: collect: html: build/docs/groovydoc '''.trim() def generator = new lifecycleGenerator() generator.loadLifecyclesString(new File('resources/lifecycles-ubuntu1604-stable.json').text) generator.loadToolchainsString(new File('resources/toolchains-ubuntu1604-stable.json').text) generator.loadYamlString(yaml) def pipeline_generator = new pipelineGenerator(generator) pipeline_generator.supported_collections = ['html'] pipeline_generator.collect_settings_filesets = [html: ['includes']] pipeline_generator.collect_settings_defaults = [html: [includes: 'foo']] pipeline_generator.collect_settings_validation = [html: [path: '''^[^,\\:*?"'<>|]+$''']] pipeline_generator.stashmap_preprocessor = [ html: { Map settings -> settings['includes']?.tokenize(',').collect { "${settings['path'] -~ '/$' -~ '^/'}/${it}" }.join(',').toString() } ] //should return "build/docs/groovydoc/foo" pipeline_generator.stashMap['html']['includes']
Instantiates this class with a lifecycleGenerator which is used for helper functions when creating a pipeline job designed to support Jervis.
Returns a list of maps which are buildable matrices in a matrix build. This method takes into account that there are matrix exclusions and white lists in the YAML configuration.
Get a publishable item from the list of publishable items. The end result could be a String or a Map.
item
- A key from jenkins.collect in user defined YAML.Get a list of publishable items which show up in .jervis.yml. This is determined from the known items in Jervis YAML jenkins.collect items.
Processes secret properties from .jervis.yml into two lists. The first list of maps is meant to be passed to MaskPasswordsBuildWrapper for masking password output. The second list contains a list of strings meant to be passed as an argument to withEnv to inject environment variables into a build runtime. The combination of the two allows one to inject secret variables into a build runtime but mask the output of a password in the build output of the Jenkins job. Used by withEnvSecretWrapper() method.
Returns a list of stashes from Jervis YAML to be stashed either serially or in this matrix axis for matrix builds.
This method merges Map m with the existing map collect_settings_defaults.
This filter ensures an admin only sets proper closures for the stashmap_processor. A stashmap_processor is for jenkins.collect items in user YAML. Sometimes a publisher needs to customize how it stashes files. This preprocessor allows an admin how a stash "includes" file pattern is determined from the settings of an item.
Jervis API documentation.