192 lines
7.0 KiB
Groovy
192 lines
7.0 KiB
Groovy
#!groovy
|
|
|
|
def repository = "registry.c.test-chamber-13.lan"
|
|
def repositoryCreds = "harbor-repository-creds"
|
|
|
|
def workspace
|
|
def k8slensVersion
|
|
def jsNodeID
|
|
def doBuild = false
|
|
def buildCommand
|
|
|
|
def label = "kubernetes-${UUID.randomUUID().toString()}"
|
|
def templateName = "pipeline-worker"
|
|
pipeline {
|
|
agent {
|
|
kubernetes {
|
|
yaml functions.podYaml(
|
|
repo: repository,
|
|
templateName: templateName,
|
|
alpine: true,
|
|
[
|
|
[
|
|
name: "node-16",
|
|
path: "${repository}/dockerhub/library/node:16",
|
|
command: "/bin/sh"
|
|
]
|
|
]
|
|
)
|
|
}
|
|
}
|
|
|
|
stages {
|
|
stage ('Initalize Jenkins') {
|
|
steps {
|
|
script {
|
|
workspace = pwd()
|
|
}
|
|
}
|
|
}
|
|
|
|
stage ('Get latest Tag') {
|
|
steps {
|
|
container ('alpine') {
|
|
script {
|
|
sh """
|
|
if ! command -v curl &> /dev/null; then
|
|
apk add --no-cache curl
|
|
fi
|
|
if ! command -v jq &> /dev/null; then
|
|
apk add --no-cache jq
|
|
fi
|
|
"""
|
|
k8slensVersion = sh (
|
|
script: """
|
|
curl \
|
|
--location \
|
|
--silent \
|
|
--fail \
|
|
--request GET \
|
|
--url https://api.github.com/repos/lensapp/lens/releases/latest | \
|
|
jq -r 'select(.prerelease == false) | .tag_name[1:]'
|
|
""",
|
|
returnStdout: true
|
|
).trim()
|
|
}
|
|
}
|
|
script {
|
|
//if (k8slensVersion ==~ '([5-9]|[0-9]{2,})\\.[0-9]+\\.[0-9]+$') {
|
|
// v6.5.x or 6.5.x-xxx
|
|
if (k8slensVersion ==~ '6\\.5\\.([0-9]+|[0-9]+-[0-9]+)$') {
|
|
echo "Version (${k8slensVersion}) is valid, we will build it with node 16."
|
|
doBuild = true
|
|
jsNodeID = 'node-16'
|
|
buildCommand = "npm install && npm run build && npm run build:app"
|
|
// } else {
|
|
// echo "Version (${k8slensVersion}) is not valid, we will not build it."
|
|
// }
|
|
} else {
|
|
echo "Version (${k8slensVersion}) is not valid, we will not build it."
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Pull K8S Lens Source Code') {
|
|
when {
|
|
expression {
|
|
return doBuild
|
|
}
|
|
}
|
|
steps {
|
|
script {
|
|
dir(workspace + "/lens") {
|
|
checkout ([
|
|
$class: "GitSCM",
|
|
branches: [
|
|
[
|
|
name: "refs/tags/v" + k8slensVersion,
|
|
],
|
|
],
|
|
userRemoteConfigs: [
|
|
[
|
|
url: "ssh://git@gitea.smoothnet.org:31822/nhyatt/openlens.git",
|
|
credentialsId: "Gitea-Read-Only-Token",
|
|
],
|
|
],
|
|
extensions: [
|
|
[
|
|
$class: "CloneOption",
|
|
shallow: true,
|
|
],
|
|
[
|
|
$class: "CheckoutOption",
|
|
timeout: 2,
|
|
],
|
|
],
|
|
])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage ('Build K8S Lens') {
|
|
when {
|
|
expression {
|
|
return doBuild
|
|
}
|
|
}
|
|
steps {
|
|
container (jsNodeID) {
|
|
script {
|
|
sh """
|
|
printf '%s\\n' "Installing required packages"
|
|
apt-get update
|
|
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install --no-install-recommends -y rpm
|
|
printf '%s\\n' "Setting up ROOT user build permissions"
|
|
mkdir -p /root/.npm/_logs
|
|
chmod 755 /root
|
|
chown -R 1000:1000 /root/.npm
|
|
printf '%s\\n' "Upgrading NPM"
|
|
npm install -g npm@^9.6.7
|
|
printf '%s\\n' "Changing user to node"
|
|
su - node
|
|
printf '%s\\n' "Setting up NODE user build permissions"
|
|
mkdir -p "/home/node/.npm"
|
|
printf '%s\\n' "Configuring NODE"
|
|
npm config set prefix="/home/node/.npm"
|
|
npm cache verify
|
|
printf '%s\\n' "Changing directory"
|
|
cd "${workspace}/lens"
|
|
printf '%s\\n' "Building..."
|
|
${buildCommand}
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage ('Push Artifacts') {
|
|
when {
|
|
expression {
|
|
return doBuild
|
|
}
|
|
}
|
|
steps {
|
|
container('alpine') {
|
|
script {
|
|
def aName = sh (
|
|
script: """
|
|
printf '%s\\n' "\$(basename "\$(find ./ -name "*.AppImage")")"
|
|
""",
|
|
returnStdout: true
|
|
).trim()
|
|
def aPath = sh (
|
|
script: """
|
|
printf '%s\\n' "\$(dirname "\$(find ./ -name "*.AppImage")")"
|
|
""",
|
|
returnStdout: true
|
|
).trim()
|
|
functions.pushArtifact(
|
|
repoCreds: "nexus-generic-upload-bot",
|
|
fileName: aName,
|
|
filePath: workspace + "/" + aPath + "/",
|
|
fileURL: "https://nexus.c.test-chamber-13.lan/repository/generic/appimage/"
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|