Created
April 1, 2019 08:15
-
-
Save amitlt/1c07ac27cec314f23d93a25eb8294e9f to your computer and use it in GitHub Desktop.
Jenkinsfile Parameter Multiple Extended Choice Example shared library step
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
node { | |
timeout(time: 5, unit: "MINUTES") { | |
INPUT_PARAMS = input( | |
message: 'Please provide the parameter input:', | |
ok: 'Next', | |
parameters: [ | |
booleanParam(defaultValue: true, name: 'Create Jira Tickets?', description: ''), | |
booleanParam(defaultValue: true, name: 'Encrypted?', description: 'Use for secrets/passwords/certificates/etc'), | |
multipleChoice(name: 'Environments', choices: ["prod", "eu", "test", "mgmt"], description: 'Environments to create parameter in'), | |
string(name: 'Path', description: 'SSM Parameter Path'), | |
text(name: 'Value', description: 'Parameter Value') | |
] | |
) | |
} | |
} |
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
import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition | |
def defaultParams() { | |
return [ | |
visibleItems: 3, | |
delimiter: ",", | |
description: "", | |
quoteValue: false | |
] | |
} | |
def call(Map params = [:]) { | |
params = defaultParams() + params | |
assert checkForMissingParameters(params: params, mandatory: ["name", "choices"]) | |
return new ExtendedChoiceParameterDefinition( | |
params.name, | |
"PT_MULTI_SELECT", | |
params.choices.join(params.delimiter), | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
"", | |
false, | |
params.quoteValue, | |
params.visibleItems, | |
params.description, | |
params.delimiter) | |
} | |
def checkForMissingParameters(Map params, String[] keys) { | |
def mandatoryKeys = ["params", "mandatory"] | |
assert params.keySet().containsAll(mandatoryKeys) // check if all required keys were passed to checkForMissingParameters step - no fancy prints | |
def missingKeys = params.mandatory.findAll({key -> !key in params.params.keySet().contains(key)}) | |
if (missingKeys.size() != 0) { | |
error(errorMessage); | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment