Skip to content

Commit

Permalink
Merge pull request #41 from hbfernandes/master
Browse files Browse the repository at this point in the history
[CLEANUP] Fix resolveTemplate not assuming ConfigurationMap as a param. Moved to Groovy SimpleTemplateEngine.
  • Loading branch information
srini-hv authored Jun 28, 2021
2 parents bd0ec10 + fc5fd06 commit a8f49b9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
15 changes: 8 additions & 7 deletions resources/templates/minion-multibranch-pipeline-default.vm
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#foreach ( $library in $libraries )
library(identifier: '$library', changelog: false)
#end
<%
libraries.each { library ->
println "library(identifier: '$library', changelog: false)"
}

#set( $runCheckout = $properties.getBool('RUN_STAGE_CHECKOUT') )
#set( $runBuild = $properties.getBool('RUN_STAGE_BUILD') )
#set( $runSonar = $properties.getBool('RUN_STAGE_SONAR') && $item.auditable )
##
runCheckout = properties.getBool('RUN_STAGE_CHECKOUT')
runBuild = properties.getBool('RUN_STAGE_BUILD')
runSonar = properties.getBool('RUN_STAGE_SONAR') && item.auditable
%>
Map defaultParams = [
SLAVE_NODE_LABEL : '$properties.getString('SLAVE_NODE_LABEL')',
WORKSPACE : '$properties.getString('WORKSPACE')',
Expand Down
25 changes: 13 additions & 12 deletions resources/templates/minion-pipeline-default.vm
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#foreach ( $library in $libraries )
library(identifier: '$library', changelog: false)
#end
<%
libraries.each { library ->
println "library(identifier: '$library', changelog: false)"
}

#set( $runCheckout = $properties.getBool('RUN_STAGE_CHECKOUT') )
#set( $runBuild = $properties.getBool('RUN_STAGE_BUILD') )
#set( $runTest = $properties.getBool('RUN_STAGE_TEST') && $item.testable )
#set( $runArchive = $properties.getBool('RUN_STAGE_ARCHIVE') && $item.archivable )
##
runCheckout = properties.getBool('RUN_STAGE_CHECKOUT')
runBuild = properties.getBool('RUN_STAGE_BUILD')
runTest = properties.getBool('RUN_STAGE_TEST') && item.testable
runArchive = properties.getBool('RUN_STAGE_ARCHIVE') && item.archivable
%>
Map defaultParams = [
SLAVE_NODE_LABEL : '$properties.getString('SLAVE_NODE_LABEL')',
WORKSPACE : '$properties.getString('WORKSPACE')',
BUILD_DATA_ROOT_PATH: '$properties.getString('BUILD_DATA_ROOT_PATH')',
BUILD_DATA_FILE : '$properties.getString('BUILD_DATA_FILE')',
SLAVE_NODE_LABEL : '$properties.SLAVE_NODE_LABEL',
WORKSPACE : '$properties.WORKSPACE',
BUILD_DATA_ROOT_PATH: '$properties.BUILD_DATA_ROOT_PATH',
BUILD_DATA_FILE : '$properties.BUILD_DATA_FILE',

RUN_STAGE_CHECKOUT : $runCheckout,
RUN_STAGE_BUILD : $runBuild,
Expand Down
37 changes: 20 additions & 17 deletions src/org/hitachivantara/ci/jenkins/MinionHandler.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import org.hitachivantara.ci.config.BuildData
import org.hitachivantara.ci.config.ConfigurationException
import org.hitachivantara.ci.config.ConfigurationMap
import org.jenkinsci.plugins.workflow.cps.CpsScript
import groovy.text.SimpleTemplateEngine
import groovy.text.TemplateEngine

import java.nio.file.Paths

Expand Down Expand Up @@ -89,34 +91,35 @@ class MinionHandler {
String rootFolderPath = getRootFolderPath()

// use the defined template or the default ones
Map templateSource
String templateSource
if(buildData.isSet(MINION_PIPELINE_TEMPLATE)){
templateSource = [file: buildData.getString(MINION_PIPELINE_TEMPLATE)]
templateSource = steps.readFile(file: buildData.getString(MINION_PIPELINE_TEMPLATE), encoding: 'UTF-8')
} else {
templateSource = [text: getDefaultPipelineTemplate()]
templateSource = getDefaultPipelineTemplate()
}

// add all the current build libraries
List libraries = JobUtils.getLoadedLibraries(steps.currentBuild)

workJobItems.each { JobItem item ->
steps.log.debug "Creating minion job for ${item.jobID}"

Map extraProps = [(BUILD_DATA_ROOT_PATH): getBuildDataPath(),
(BUILD_DATA_FILE) : getBuildDataFilename(item)]

String script = steps.resolveTemplate(templateSource + [
parameters: [
libraries : libraries,
properties : buildData.buildProperties + extraProps,
item : item.export()
]
])

Map parameters = [
libraries : libraries,
properties: new ConfigurationMap(buildData.buildProperties, [
(BUILD_DATA_ROOT_PATH): getBuildDataPath(),
(BUILD_DATA_FILE) : getBuildDataFilename(item),
]),
item: item.export()
]

TemplateEngine engine = new SimpleTemplateEngine()
Writable template = engine.createTemplate(templateSource).make(parameters)

Map jobConfig = [
name: getJobName(item),
folder: rootFolderPath,
script: script
script: template.toString()
]

if (buildData.getBool(USE_MINION_MULTIBRANCH_JOBS)) {
Expand All @@ -135,8 +138,8 @@ class MinionHandler {
prMerge : item.prMerge
]
]
}
}

steps.createJob(jobConfig)
}

Expand Down

0 comments on commit a8f49b9

Please sign in to comment.