moves to declarative pipeline

This commit is contained in:
Hyatt 2022-03-30 06:53:41 -05:00
parent 4c911d1280
commit b620de0f11
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA

View File

@ -3,7 +3,31 @@
def repository = "registry.c.test-chamber-13.lan"
def repositoryCreds = "harbor-repository-creds"
def route_override = """#! /usr/bin/env sh
def workspace
def dockerFile
def route_override
def connectivity_test
def label = "kubernetes-${UUID.randomUUID().toString()}"
def templateName = "pipeline-worker"
pipeline {
agent {
kubernetes {
yaml functions.podYaml(
repo: repository,
templateName: templateName,
kaniko: true
)
}
}
stages {
stage ('Initalize Jenkins') {
steps {
script {
workspace = pwd()
route_override = """#! /usr/bin/env sh
VPN_GATEWAY=\$(ip route | grep default | awk '{print \$3}')
ip route add 10.42.0.0/16 via "\${VPN_GATEWAY}" dev eth0
ip route add 10.43.0.0/16 via "\${VPN_GATEWAY}" dev eth0
@ -11,8 +35,9 @@ ip route add 10.20.0.0/16 via "\${VPN_GATEWAY}" dev eth0
ip route del default via "\${VPN_GATEWAY}"
printf "%s\n" "Route Updated"
"""
writeFile(file: workspace + "/route-override.sh", text: route_override)
def connectivity_test = """#! /usr/bin/env sh
connectivity_test = """#! /usr/bin/env sh
getPublicIP() {
ip=""
@ -77,8 +102,9 @@ if ! ping -c 2 google.com > /dev/null; then
exit 100
fi
"""
writeFile(file: workspace + "/connectivity_test.sh", text: connectivity_test)
def dockerFile = """FROM ${repository}/linuxserver/linuxserver/deluge:amd64-latest
dockerFile = """FROM ${repository}/linuxserver/linuxserver/deluge:amd64-latest
LABEL maintainer="The_Spider <spider@smoothnet.org>"
COPY route-override.sh connectivity_test.sh /root/
@ -87,28 +113,29 @@ RUN apk add --no-cache openvpn iputils bind-tools curl && \\
chmod +x /root/route-override.sh /root/connectivity_test.sh
"""
def label = "kubernetes-${UUID.randomUUID().toString()}"
def templateName = "pipeline-worker"
podTemplate(
label: label,
name: templateName,
yaml: functions.podYaml(
repo: repository,
templateName: templateName,
kaniko: true
)
) {
node (label) {
def workspace = pwd()
}
}
}
writeFile(file: workspace + "/route-override.sh", text: route_override)
writeFile(file: workspace + "/connectivity_test.sh", text: connectivity_test)
functions.buildContainer(
repository: repository,
imageDest: "${repository}/library/deluge:latest",
stage ('Build & Push') {
steps {
container ('kaniko') {
script {
declarativeFunctions.buildContainerMultipleDestinations(
dockerFile: dockerFile,
repoCreds: repositoryCreds,
repositoryAccess: [
[
repository: repository,
credentials: repositoryCreds
],
],
destination: [
"${repository}/library/deluge:latest",
]
)
}
}
}
}
}
}