Last active
November 2, 2022 06:51
-
-
Save turboBasic/4e25b84aae042de7679e4139ac9cddb5 to your computer and use it in GitHub Desktop.
Create reusable parameter definitions in Job DSL script #jenkins #job-dsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // taken from https://groups.google.com/g/job-dsl-plugin/c/eJvX7G7OwQU?pli=1 | |
| def aParam = { | |
| stringParam('aa') | |
| } | |
| def moreParams = { | |
| stringParam('bb') | |
| stringParam('cc') | |
| } | |
| job('one') { | |
| parameters(aParam) | |
| parameters(moreParams) | |
| } | |
| job('two') { | |
| parameters(aParam) | |
| parameters(moreParams) | |
| } | |
| // | |
| class DslUtil { | |
| static configureTfsParams(jobContext) { | |
| configureValidatingParam(jobContext, [ | |
| name:'TFS_SERVER_URL', | |
| description:'Example Desc A', | |
| regex:'.+', | |
| failedValidationMessage:'Give me A' | |
| ]) | |
| configureValidatingParam(jobContext, [ | |
| name:'EXAMPLE_PROJECT_PATH', | |
| description:'Example Desc B', | |
| regex:'.+', | |
| failedValidationMessage:'Give me B' | |
| ]) | |
| } | |
| static configureValidatingParam(jobContext, params) { | |
| jobContext.with { | |
| configure { | |
| it / 'properties' / 'hudson.model.ParametersDefinitionProperty' / 'parameterDefinitions' << 'hudson.plugins.validating__string__parameter.ValidatingStringParameterDefinition' { | |
| 'name'(params.name) | |
| 'description'(params.description) | |
| 'defaultValue'(params.defaultValue) | |
| 'regex'(params.regex) | |
| 'failedValidationMessage'(params.failedValidationMessage) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| job('test') { | |
| DslUtil.configureTfsParams delegate | |
| DslUtil.configureValidatingParam(delegate, [ | |
| name:'APP_NAME', | |
| description:'Name of the application to deploy', | |
| regex:'.+', | |
| failedValidationMessage:'Must supply an application to deploy' | |
| ]) | |
| DslUtil.configureValidatingParam(delegate, [ | |
| name:'APP_VERSION', | |
| description:'Version of the application to deploy', | |
| regex:'.+', | |
| failedValidationMessage:'Must supply a version to deploy' | |
| ]) | |
| DslUtil.configureValidatingParam(delegate, [ | |
| name:'TARGET_VM', | |
| description:'Server that should have application after deploy', | |
| regex:'.+', | |
| failedValidationMessage:'Must supply a server to deploy' | |
| ]) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment