adds logic to install curl/kubectl only if it does not already exist fro multiple calls and adds create secret

This commit is contained in:
Hyatt 2022-03-15 16:28:45 -05:00
parent b5f2ed9727
commit cbbb21e12d
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA
2 changed files with 32 additions and 28 deletions

View File

@ -54,9 +54,13 @@ def deletePod (Map config) {
stage ("Delete Pod") {
container ("alpine") {
sh """
apk add --no-cache curl
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
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 ([
@ -70,6 +74,31 @@ def deletePod (Map config) {
}
}
def createSecret (Map config) {
def ws = pwd()
stage ("Create Secret") {
container ("alpine") {
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
]) {
sh "printf '%s\n' \"" + config.secret + "\" | kubectl apply -f -"
}
}
}
}
def buildContainer (Map config, List buildArg = []) {
def ws = pwd()
stage ("Build Container") {

View File

@ -1,25 +0,0 @@
def call(body) {
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body ()
/*
def reposConfig = [:]
config.reposConfig.each{repo ->
reposConfig[repo.key] = [
gitBranch: repo.value.gitBranch,
gitRepo: repo.value.gitRepo,
gitCreds: repo.value.gitCreds,
testValue: repo.value?.testValue ?: "default"
]
}
*/
Map reposConfig = config.reposConfig ?: [:]
reposConfig.each{repo ->
def name = repo.key
echo "Map Element ${name}: ${repo.value.gitRepo} = ${repo.value.testValue}"
}
}