Adds delete-pod functionality
This commit is contained in:
parent
f6b7d53f11
commit
5edd8b0e58
@ -1,5 +1,53 @@
|
||||
#!groovy
|
||||
|
||||
def deletePod(
|
||||
String kubeAuth,
|
||||
String kubeURL,
|
||||
String namespace,
|
||||
String selector,
|
||||
){
|
||||
def label = "kubernetes-${UUID.randomUUID().toString()}"
|
||||
def ws = pwd()
|
||||
|
||||
podTemplate(
|
||||
label: label,
|
||||
name: "pipeline-worker",
|
||||
yaml: """
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: pipeline-worker
|
||||
spec:
|
||||
containers:
|
||||
- name: alpine
|
||||
imagePullPolicy: Always
|
||||
image: ${repository}/library/alpine:latest
|
||||
tty: true
|
||||
command:
|
||||
- /busybox/sh
|
||||
""",
|
||||
){
|
||||
node(label) {
|
||||
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: kubeAuth,
|
||||
serverUrl: kubeURL,
|
||||
namespace: namespace,
|
||||
]) {
|
||||
sh "for i in \$(kubectl get pods --selector ${selector} -o name); do kubectl delete \${i}; done"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def buildContainer(String repository,
|
||||
String imageDest,
|
||||
String dockerFile,
|
||||
@ -28,7 +76,7 @@ spec:
|
||||
""",
|
||||
){
|
||||
node(label) {
|
||||
container ("kaniko") {
|
||||
container("kaniko") {
|
||||
writeFile(file: ws + "/Dockerfile", text: DF)
|
||||
withCredentials([usernameColonPassword(
|
||||
credentialsId: repoCreds,
|
||||
|
Loading…
x
Reference in New Issue
Block a user