jenkins-lib

Jenkins shared library
git clone https://git.in0rdr.ch/jenkins-lib.git
Log | Files | Refs | Pull requests |Archive | README

commit 46ff8eab8cf689499e07eb3b6383473e56688d78
parent b8d854d1d2dd26c206f3663aa0456ebaa54c42cb
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Thu, 14 Aug 2025 08:01:40 +0200

feat(packer): add build dir

Diffstat:
Msrc/BuildahBud.groovy | 2+-
Msrc/PackerBuild.groovy | 22+++++++++++++---------
2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/BuildahBud.groovy b/src/BuildahBud.groovy @@ -7,7 +7,7 @@ class BuildahBud implements Serializable { } // Build with named buildArgs (first) - // Mandatory: Image name and tag + // Mandatory: Image context and name // Optional: Image tag, architecture, registry, .. void execute(Map buildArgs = [], String imgContext, diff --git a/src/PackerBuild.groovy b/src/PackerBuild.groovy @@ -8,20 +8,24 @@ class PackerBuild implements Serializable { // Build with named buildArgs (first) // Mandatory: Build template - // Optional: PACKER_LOG - void execute(Map buildVars = [], - String buildTemplate, - String packerLog = '0', // PACKER_LOG - String stageName = 'build') { + // Optional: Build vars, PACKER_LOG, build dir + void execute(Map buildVars = [], + String buildTemplate, + Integer packerLog = 0, + String buildDir= '.', + String stageName = 'build') { def varList = buildVars.collect{ k, v -> "-var '${k}=${v}'" }.join(' ') - def shCmd = sprintf( - '%s packer build %s %s', - packerLog, varList, buildTemplate, argList) + def shBuildCmd = sprintf( + 'PACKER_LOG=%d /usr/local/bin/packer build %s %s', + packerLog, varList, buildTemplate, varList) script.stage(stageName) { + script.sh 'cd ${buildDir}' + script.echo "Initializing from template ${buildTemplate} in build dir '${buildDir}'..." + script.sh "/usr/local/bin/packer init ${buildTemplate}" script.echo "Building from template ${buildTemplate}..." - script.sh shCmd + script.sh shBuildCmd } } }