From b5545c64ca32734a8ce13bf1c882aa9de4c4e60b Mon Sep 17 00:00:00 2001 From: The_Spider Date: Tue, 11 Jan 2022 17:50:18 -0600 Subject: [PATCH] adds stages --- vars/functions.groovy | 54 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/vars/functions.groovy b/vars/functions.groovy index 363fe06..a24c1f3 100644 --- a/vars/functions.groovy +++ b/vars/functions.groovy @@ -34,38 +34,42 @@ spec: def deletePod (Map config) { def ws = pwd() - container ("alpine") { - sh """ - apk add --no-cache curl - curl -L --silent https://storage.googleapis.com/kubernetes-release/release/\$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl - chmod +x /usr/local/bin/kubectl - """ + stage ("Delete Pod") { + container ("alpine") { + sh """ + apk add --no-cache curl + curl -L --silent https://storage.googleapis.com/kubernetes-release/release/\$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl + chmod +x /usr/local/bin/kubectl + """ - withKubeConfig ([ - credentialsId: config.kubeAuth, - serverUrl: config.kubeURL, - namespace: config.namespace, - ]) { - sh "for i in \$(kubectl get pods --selector ${config.selector} -o name); do kubectl delete \${i}; done" + withKubeConfig ([ + credentialsId: config.kubeAuth, + serverUrl: config.kubeURL, + namespace: config.namespace, + ]) { + sh "for i in \$(kubectl get pods --selector ${config.selector} -o name); do kubectl delete \${i}; done" + } } } } def buildContainer (Map config) { def ws = pwd() - container("kaniko") { - writeFile (file: ws + "/Dockerfile", text: config.dockerFile) - withCredentials([usernameColonPassword( - credentialsId: config.repoCreds, - variable: "dCreds", - )]) { - sh "set +x; printf '{\"auths\":{\"%s\":{\"auth\": \"%s\"}}}' \"${config.repository}\" \"${dcreds.bytes.encodeBase64().toString()}\" > /kaniko/.docker/config.json" + stage ("Build Container") { + container ("kaniko") { + writeFile (file: ws + "/Dockerfile", text: config.dockerFile) + withCredentials([usernameColonPassword( + credentialsId: config.repoCreds, + variable: "dCreds", + )]) { + sh "set +x; printf '{\"auths\":{\"%s\":{\"auth\": \"%s\"}}}' \"${config.repository}\" \"${dcreds.bytes.encodeBase64().toString()}\" > /kaniko/.docker/config.json" + } + sh """ + /kaniko/executor \\ + --context "${ws}" \\ + -f "${ws}/Dockerfile" \\ + --destination "${config.imageDest}" + """ } - sh """ - /kaniko/executor \\ - --context "${ws}" \\ - -f "${ws}/Dockerfile" \\ - --destination "${config.imageDest}" - """ } }