PackerBuild.groovy (1269B)
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 buildVars (first) 10 // Mandatory: Build template 11 // Optional: Build vars, PACKER_LOG 12 void execute(Map buildVars = [], 13 String buildTemplate, 14 Integer packerLog = 0, 15 String stageName = 'build') { 16 17 def varList = buildVars.collect{ k, v -> "-var '${k}=${v}'" }.join(' ') 18 def shInitCmd = sprintf( 19 ''' 20 PACKER_NO_COLOR=1 /usr/local/bin/packer init %s 21 ''', 22 buildTemplate 23 ) 24 def shBuildCmd = sprintf( 25 ''' 26 PACKER_NO_COLOR=1 PACKER_LOG=%d /usr/local/bin/packer build %s %s 27 ''', 28 packerLog, varList, buildTemplate, varList 29 ) 30 31 script.stage(stageName) { 32 //script.echo "User ID inside script stage '$stageName':" 33 //script.sh "id" 34 //script.echo "Available lxc download templates:" 35 //script.sh "/usr/share/lxc/templates/lxc-download -l" 36 37 script.echo "Initializing from template ${buildTemplate}..." 38 script.sh shInitCmd 39 40 script.echo "Building from template ${buildTemplate}..." 41 script.sh shBuildCmd 42 } 43 } 44 }