String buildCadolesPodPackage(String imageName, String imageTag, Map options = [:]) { String destDir = options.get('destDir', env.WORKSPACE + '/dist') Map nfpmOptions = options.get('nfpmOptions', [:]) nfpmOptions['target'] = destDir Map env = options.get('env', [:]) env['IMAGE_NAME'] = imageName env['IMAGE_TAG'] = imageTag return withPodmanPackagingTempDir { gomplate('post-install.sh.gotmpl', 'post-install.sh', env) gomplate('pod.service.gotmpl', 'pod.service', env) gomplate('pod.conf.gotmpl', 'pod.conf', env) gomplate('nfpm.yaml.gotmpl', 'nfpm.yaml', env) nfpm(nfpmOptions) } } void withPodmanPackagingTempDir(Closure fn) { File tempDir = File.createTempDir() tempDir.deleteOnExit() tempDir.mkdirs() dir(tempDir.getAbsolutePath()) { List resources = [ 'com/cadoles/podman/nfpm.yaml.gotmpl', 'com/cadoles/podman/pod.conf.gotmpl', 'com/cadoles/podman/pod.service.gotmpl', 'com/cadoles/podman/post-install.sh.gotmpl', ] for (res in resources) { String fileContent = libraryResource res String fileName = res.substring(res.lastIndexOf('/') + 1) writeFile file:fileName, text:fileContent } fn() } }