Jenkins/vars/nfpm.groovy

26 lines
1.1 KiB
Groovy

// Package project with nfpm
// See https://nfpm.goreleaser.com/
def package(Map options = [:]) {
String installDir = options.get("nfpmInstallDir", "/usr/local/bin")
String nfpmVersion = options.get("nfpmVersion", "2.15.1")
String nfpmForceDownload = options.get("nfpmForceDownload", false)
String nfpmDownloadUrl = options.get("nfpmDownloadUrl", "https://github.com/goreleaser/nfpm/releases/download/${nfpmVersion}/nfpm_${nfpmVersion}_Linux_x86_64.tar.gz")
String nfpmConfig = options.get("nfpmConfig", "nfpm.yaml")
String nfpmTarget = options.get("nfpmTarget", ".")
String nfpmPackager = options.get("nfpmPackager", "")
String nfpmBin = sh(returnStdout: true, script: 'which nfpm').trim("")
if (nfpmBin == "" || nfpmForceDownload) {
sh("""
mkdir -p '${installDir}'
curl -L '${nfpmDownloadUrl}' > /tmp/nfpm.tar.gz
tar -C /usr/local/bin -xzf /tmp/nfpm.tar.gz
""")
}
sh("""
export PATH='${installDir}:${env.PATH}'
nfpm --config '${nfpmConfig}' ${nfpmPackager ? "--packager "+nfpmPackager : ""} --target '${nfpmTarget}'
""")
}