jenkins-lib

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

BuildahBud.groovy (976B)


      1 // A class to describe the buildah bud stage
      2 class BuildahBud implements Serializable {
      3   private final Script script
      4 
      5   BuildahBud(Script script) {
      6     this.script = script
      7   }
      8 
      9   // Build with named buildArgs (first)
     10   // Mandatory: Image context and name
     11   // Optional: Image tag, architecture, registry, ..
     12   void execute(Map    buildArgs = [],
     13                String imgContext,
     14                String imgName,
     15                String imgTag = 'latest',
     16                String imgArch = 'arm64/v8',
     17                String imgRegistry = 'haproxy.lan:5000',
     18                String stageName = 'build') {
     19 
     20     def argList = buildArgs.collect{ k, v -> "--build-arg=${k}=${v}" }.join(' ')
     21     def shCmd = sprintf(
     22         'buildah bud --no-cache --arch=%s %s -t %s/%s:%s %s',
     23         imgArch, argList, imgRegistry, imgName, imgTag, imgContext)
     24 
     25     script.stage(stageName) {
     26       script.echo "Building image ${imgRegistry}/${imgName}:${imgTag}..."
     27       script.sh shCmd
     28     }
     29   }
     30 }