From 7f5caa0829d721885fd5f827f1b4f9b1f22cf563 Mon Sep 17 00:00:00 2001 From: nhyatt Date: Sun, 22 Oct 2023 11:36:00 -0500 Subject: [PATCH] adds read secret command --- vars/declarativeFunctions.groovy | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/vars/declarativeFunctions.groovy b/vars/declarativeFunctions.groovy index 1a9c64b..0f66070 100644 --- a/vars/declarativeFunctions.groovy +++ b/vars/declarativeFunctions.groovy @@ -47,6 +47,34 @@ def createSecret (Map config) { } } +def readSecret (Map config) { + def ws = pwd() + sh """ + if [ ! -f "/usr/bin/curl" ] || [ ! -x "/usr/bin/curl" ]; then + apk add --no-cache curl + fi + if [ ! -f "/usr/local/bin/kubectl" ] || [ ! -x "/usr/local/bin/kubectl" ]; then + curl -L --silent https://nexus.c.test-chamber-13.lan/repository/google-k8s/\$(curl -s https://nexus.c.test-chamber-13.lan/repository/google-k8s/stable.txt)/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl + chmod +x /usr/local/bin/kubectl + fi + """ + + withKubeConfig ([ + credentialsId: config.kubeAuth, + serverUrl: config.kubeURL, + namespace: config.namespace + ]) { + def output = sh( + returnStdout: true, + script: """#Read Secret + set +x + kubectl get secret "${config.secretName}" -o jsonpath={".data.${configSecretID}"} | base64 -d + """ + ) + return output + } +} + def buildContainer (Map config, List buildArg = []) { def ws = pwd() writeFile (file: ws + "/Dockerfile", text: config.dockerFile)