diff --git a/vars/functions.groovy b/vars/functions.groovy index 901873e..ea83224 100644 --- a/vars/functions.groovy +++ b/vars/functions.groovy @@ -1,4 +1,5 @@ #!groovy +import groovy.json.JsonOutput def podYaml (Map config, List customImages = [[:]]) { def output = """ @@ -15,7 +16,6 @@ spec: imagePullPolicy: Always image: ${config.repo}/library/kaniko:latest tty: true - stdin_open: true command: - /busybox/sh""" } @@ -109,7 +109,7 @@ def buildContainer (Map config, List buildArg = []) { credentialsId: config.repoCreds, variable: "dCreds" )]) { - sh "printf '{\"auths\":{\"%s\":{\"auth\": \"%s\"}}}' \"${config.repository}\" \"${dcreds.bytes.encodeBase64().toString()}\" > /kaniko/.docker/config.json" + sh "set +x; printf '{\"auths\":{\"%s\":{\"auth\": \"%s\"}}}' \"${config.repository}\" \"${dcreds.bytes.encodeBase64().toString()}\" > /kaniko/.docker/config.json" } def buildArguments = "" for (i in buildArg) { @@ -126,6 +126,39 @@ def buildContainer (Map config, List buildArg = []) { } } +def buildContainerMultipleDestinations (Map config, List buildArg = []) { + def ws = pwd() + stage ("Build Containers") { + container ("kaniko") { + writeFile (file: ws + "/Dockerfile", text: config.dockerFile) + + def buildArguments = "" + def repoAuth = ["auths": [:]] + for (i in config.repositoryAccess) { + withCredentials([usernameColonPassword( + credentialsId: i.credentials, + variable: "dCreds" + )]) { + repoAuth."auths"[i.repository] = ["auth": dCreds.bytes.encodeBase64().toString()] + } + buildArguments += " --destination \"${i.repository}${i.destination}\"" + } + sh "set +x; printf '${JsonOutput.toJson(repoAuth)}' > /kaniko/.docker/config.json" + + for (i in buildArg) { + buildArguments += " --build-arg ${i}" + } + + sh """ + /kaniko/executor \\ + --context "${ws}" \\ + -f "${ws}/Dockerfile" \\ + ${buildArguments} + """ + } + } +} + def pushArtifact (Map config) { def ws = pwd() stage ("Push Artifact: " + config.fileName) {