PackerBuild.groovy (1041B)
1 // A class to describe the packer build stage 2 class PackerBuild implements Serializable { 3 private final Script script 4 5 PackerBuild(Script script) { 6 this.script = script 7 } 8 9 // Build with named buildArgs (first) 10 // Mandatory: Build template 11 // Optional: Build vars, PACKER_LOG, build dir 12 void execute(Map buildVars = [], 13 String buildTemplate, 14 Integer packerLog = 0, 15 String buildDir= '.', 16 String stageName = 'build') { 17 18 def varList = buildVars.collect{ k, v -> "-var '${k}=${v}'" }.join(' ') 19 def shBuildCmd = sprintf( 20 'PACKER_LOG=%d /usr/local/bin/packer build %s %s', 21 packerLog, varList, buildTemplate, varList) 22 23 script.stage(stageName) { 24 script.sh 'cd ${buildDir}' 25 script.echo "Initializing from template ${buildTemplate} in build dir '${buildDir}'..." 26 script.sh "/usr/local/bin/packer init ${buildTemplate}" 27 script.echo "Building from template ${buildTemplate}..." 28 script.sh shBuildCmd 29 } 30 } 31 }