jenkins-lib

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

BuildahBud.groovy (1111B)


      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: Dockerfile path, Image tag, architecture, registry, ..
     12   void execute(Map    buildArgs = [],
     13                String imgContext,
     14                String imgName,
     15                String imgTag = 'latest',
     16                String dockerFile = 'Dockerfile',
     17                String imgArch = 'arm64/v8',
     18                String imgRegistry = 'haproxy.lan:5000',
     19                String stageName = 'build') {
     20 
     21     // $v can contain additional quoted strings
     22     def argList = buildArgs.collect{ k, v -> "--build-arg ${k}=\"${v}\""}.join(' ')
     23     def shCmd = sprintf(
     24         'buildah bud --no-cache --arch=%s %s -t %s/%s:%s -f %s %s',
     25         imgArch, argList, imgRegistry, imgName, imgTag, dockerFile, imgContext)
     26 
     27     script.stage(stageName) {
     28       script.echo "Building image ${imgRegistry}/${imgName}:${imgTag}..."
     29       script.sh shCmd
     30     }
     31   }
     32 }