cant use podtemplate in a function
This commit is contained in:
parent
4ea9e666e3
commit
30b78e6bde
@ -1,34 +1,39 @@
|
|||||||
#!groovy
|
#!groovy
|
||||||
|
|
||||||
def deletePod(
|
def podYaml (Map config) {
|
||||||
String kubeAuth,
|
def output = """
|
||||||
String kubeURL,
|
|
||||||
String namespace,
|
|
||||||
String selector
|
|
||||||
){
|
|
||||||
def label = "kubernetes-${UUID.randomUUID().toString()}"
|
|
||||||
def ws = pwd()
|
|
||||||
|
|
||||||
podTemplate(
|
|
||||||
label: label,
|
|
||||||
name: "pipeline-worker",
|
|
||||||
yaml: """
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Pod
|
kind: Pod
|
||||||
metadata:
|
metadata:
|
||||||
name: pipeline-worker
|
name: ${config.templateName}
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: alpine
|
"""
|
||||||
|
if (config.kaniko == true) {
|
||||||
|
output += """
|
||||||
|
- name: kaniko
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
image: ${repository}/library/alpine:latest
|
image: ${config.repo}/library/kaniko:latest
|
||||||
tty: true
|
tty: true
|
||||||
command:
|
command:
|
||||||
- /busybox/sh
|
- /busybox/sh
|
||||||
""",
|
"""
|
||||||
){
|
}
|
||||||
node(label) {
|
if (config.alpine == true) {
|
||||||
|
output += """
|
||||||
|
- name: alpine
|
||||||
|
imagePullPolicy: Always
|
||||||
|
image: ${config.repo}/library/alpine:latest
|
||||||
|
tty: true
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
def deletePod (Mab config) {
|
||||||
|
def ws = pwd()
|
||||||
container ("alpine") {
|
container ("alpine") {
|
||||||
sh """
|
sh """
|
||||||
apk add --no-cache curl
|
apk add --no-cache curl
|
||||||
@ -37,60 +42,30 @@ spec:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
withKubeConfig ([
|
withKubeConfig ([
|
||||||
credentialsId: kubeAuth,
|
credentialsId: config.kubeAuth,
|
||||||
serverUrl: kubeURL,
|
serverUrl: config.kubeURL,
|
||||||
namespace: namespace,
|
namespace: config.namespace,
|
||||||
]) {
|
]) {
|
||||||
sh "for i in \$(kubectl get pods --selector ${selector} -o name); do kubectl delete \${i}; done"
|
sh "for i in \$(kubectl get pods --selector ${config.selector} -o name); do kubectl delete \${i}; done"
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def buildContainer(String repository,
|
def buildContainer (Map config) {
|
||||||
String imageDest,
|
|
||||||
String dockerFile,
|
|
||||||
String repoCreds) {
|
|
||||||
|
|
||||||
def label = "kaniko-${UUID.randomUUID().toString()}"
|
|
||||||
def ws = pwd()
|
def ws = pwd()
|
||||||
|
|
||||||
podTemplate(
|
|
||||||
label: label,
|
|
||||||
name: "pipeline-worker",
|
|
||||||
yaml: """
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Pod
|
|
||||||
metadata:
|
|
||||||
name: pipeline-worker
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: kaniko
|
|
||||||
imagePullPolicy: Always
|
|
||||||
image: ${repository}/library/kaniko:latest
|
|
||||||
tty: true
|
|
||||||
command:
|
|
||||||
- /busybox/sh
|
|
||||||
""",
|
|
||||||
){
|
|
||||||
node(label) {
|
|
||||||
container("kaniko") {
|
container("kaniko") {
|
||||||
writeFile(file: ws + "/Dockerfile", text: DF)
|
writeFile (file: ws + "/Dockerfile", text: config.dockerFile)
|
||||||
withCredentials([usernameColonPassword(
|
withCredentials([usernameColonPassword(
|
||||||
credentialsId: repoCreds,
|
credentialsId: config.repoCreds,
|
||||||
variable: "dCreds",
|
variable: "dCreds",
|
||||||
)]) {
|
)]) {
|
||||||
sh "set +x; printf '{\"auths\":{\"%s\":{\"auth\": \"%s\"}}}' \"${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"
|
||||||
}
|
}
|
||||||
sh """
|
sh """
|
||||||
/kaniko/executor \\
|
/kaniko/executor \\
|
||||||
--context "${ws}" \\
|
--context "${ws}" \\
|
||||||
-f "${ws}/Dockerfile" \\
|
-f "${ws}/Dockerfile" \\
|
||||||
--destination "${repository}/${imageDest}
|
--destination "${config.imageDest}"
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user