Skip to content

Instantly share code, notes, and snippets.

@amitlt
Created April 1, 2019 08:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save amitlt/1c07ac27cec314f23d93a25eb8294e9f to your computer and use it in GitHub Desktop.
Save amitlt/1c07ac27cec314f23d93a25eb8294e9f to your computer and use it in GitHub Desktop.
Jenkinsfile Parameter Multiple Extended Choice Example shared library step
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')
]
)
}
}
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