Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

Commit

Permalink
Add simple non-literal (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Boardwell committed Apr 20, 2020
1 parent b9a428b commit 734a594
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions src/JobDslGenUtil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,15 @@ class JobDslGenUtil {
// currently only supporting literals
// if non-literal values found set to blank string to be corrected on first build run
def valueToSet = ''
if (isLiteral) {
if (arg.value.name) {
output << " Method call found - not handling: ---------> $argKey : ${arg.value}"
} else if (isLiteral) {
valueToSet = arg.value.value
output << " Use literal: ${isLiteral} ---------> $argKey : ${valueToSet}"
} else {
valueToSet = toGroovy(arg.value.value)
output << " Use literal: ${isLiteral} ---------> $argKey : ${valueToSet}"
}
output << " Use literal: ${isLiteral} ---------> $argKey : ${valueToSet}"
argMap."$argKey" = valueToSet
}
switch (paramType) {
Expand All @@ -295,7 +300,7 @@ class JobDslGenUtil {
addChoiceParam(parametersDelegate, argMap)
break
case ~/extendedChoice/:
addExtendedChoiceParam(jobDelegate, argMap)
addExtendedChoiceParam(parametersDelegate, argMap)
break
case ~/text/:
addTextParam(parametersDelegate, argMap)
Expand All @@ -312,6 +317,19 @@ class JobDslGenUtil {
}
}

/*
* Taken from:
* https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/23540e24d7ca201404a8762e3701e6f34b407920/pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/JSONParser.groovy#L620-L648
* https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/23540e24d7ca201404a8762e3701e6f34b407920/pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTValue.java#L164-L171
*/
static private toGroovy(String gstring) {
if (gstring.startsWith('${') && gstring.endsWith('}')) {
return Eval.me(gstring.substring(2, gstring.length() - 1))
} else {
return Eval.me(gstring);
}
}

static def addOptions(job, pipelineJson, out) {
def output = []
try {
Expand Down Expand Up @@ -397,12 +415,24 @@ class JobDslGenUtil {
delegate.choiceParam(argMap.name, argMap.choices, argMap.description)
}

private static addExtendedChoiceParam(def jobDelegate, def argMap) {
private static addExtendedChoiceParam(def paramsDelegate, def argMap) {
// special case for extended choice
jobDelegate.configure { project->
project / 'properties' / 'hudson.model.ParametersDefinitionProperty' / parameterDefinitions << 'com.cwctravel.hudson.plugins.extended__choice__parameter.ExtendedChoiceParameterDefinition' {
argMap.each { k, v ->
delegate.k(v)
def options = [
'bindings', 'defaultBindings', 'defaultGroovyClasspath', 'defaultGroovyScript', 'defaultGroovyScriptFile',
'defaultPropertyFile', 'defaultPropertyKey', 'defaultValue', 'description', 'descriptionBindings',
'descriptionGroovyClasspath', 'descriptionGroovyScript', 'descriptionGroovyScriptFile',
'descriptionPropertyFile', 'descriptionPropertyKey', 'descriptionPropertyValue', 'groovyClasspath',
'groovyScript', 'groovyScriptFile', 'javascript', 'javascriptFile', 'multiSelectDelimiter', 'name',
'projectName', 'propertyFile', 'propertyKey', 'quoteValue', 'saveJSONParameterToFile', 'type',
'value', 'visibleItemCount'
]
paramsDelegate.extendedChoice {
def extendedChoiceDelegate = delegate
options.each { key ->
if (argMap.containsKey(key)) {
extendedChoiceDelegate."$key"(argMap."$key")
} else {
extendedChoiceDelegate."$key"(null)
}
}
}
Expand Down

0 comments on commit 734a594

Please sign in to comment.