Moves to declarative pipeline

This commit is contained in:
Hyatt 2022-03-29 18:26:54 -05:00
parent d8ee5d9a20
commit 8fe6aa5e96
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA

View File

@ -3,16 +3,56 @@
def repository = "registry.c.test-chamber-13.lan"
def repositoryCreds = "harbor-repository-creds"
def AlpineGlibcBaseURL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download"
def AlpineGlibcPackageVersion = "2.34-r0"
def AlpineGlibcBasePackageFilename = "glibc-${AlpineGlibcPackageVersion}.apk"
def AlpineGlibcBinPackageFilename = "glibc-bin-${AlpineGlibcPackageVersion}.apk"
def AlpineGlibcI18nPackageFilename = "glibc-i18n-${AlpineGlibcPackageVersion}.apk"
def workspace
def dockerFile
def AlpineGlibcBaseURL="https://nexus.c.test-chamber-13.lan/repository/github-releases/sgerrand/alpine-pkg-glibc/releases/download"
def AlpineGlibcPackageVersion
def AlpineGlibcBasePackageFilename
def AlpineGlibcBinPackageFilename
def AlpineGlibcI18nPackageFilename
def GlibcLanguage = "C.UTF-8"
def TimeZone = "America/Chicago"
def dockerFile = """
def label = "kubernetes-${UUID.randomUUID().toString()}"
def templateName = "pipeline-worker"
pipeline {
agent {
kubernetes {
yaml functions.podYaml(
repo: repository,
templateName: templateName,
kaniko: true,
alpine: true
)
}
}
stages {
stage ('Initalize Jenkins') {
steps {
workspace = pwd()
container ('alpine') {
script {
sh """
if [ ! -f "/usr/bin/curl" ] || [ ! -x "/usr/bin/curl" ]; then
apk add --no-cache curl
fi
if [ ! -f "/usr/bin/jq" ] || [ ! -x "/usr/bin/jq" ]; then
apk add --no-cache curl
fi
"""
AlpineGlibcPackageVersion = sh (
script: "curl --silent --location --fail \"https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases\" | jq -r .[0].name",
returnStdout: true
).trim()
AlpineGlibcBasePackageFilename = "glibc-${AlpineGlibcPackageVersion}.apk"
AlpineGlibcBinPackageFilename = "glibc-bin-${AlpineGlibcPackageVersion}.apk"
AlpineGlibcI18nPackageFilename = "glibc-i18n-${AlpineGlibcPackageVersion}.apk"
dockerFile = """
FROM registry.c.test-chamber-13.lan/library/alpine:latest
LABEL maintainer="The_Spider <spider@smoothnet.org>"
@ -51,30 +91,34 @@ RUN apk add --update --no-cache --virtual=.build-dependencies \\
${AlpineGlibcBinPackageFilename} \\
${AlpineGlibcI18nPackageFilename}
"""
}
}
}
}
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()
functions.buildContainer(
repository: repository,
imageDest: "${repository}/library/alpine-glibc:latest",
dockerFile: dockerFile,
repoCreds: repositoryCreds,
[
"LANG=${GlibcLanguage}",
"TZ=${TimeZone}"
]
)
stage ('Build & Push') {
steps {
container ('kaniko') {
script {
declarativeFunctions.buildContainerMultipleDestinations(
dockerFile: dockerFile,
repositoryAccess: [
[
repository: repository,
credentials: repositoryCreds
],
],
destination: [
"${repository}/library/alpine-glibc:latest",
],
[
"LANG=${GlibcLanguage}",
"TZ=${TimeZone}"
]
)
}
}
}
}
}
}