3
0

OP#253 add build stage prometheus rpm

This commit is contained in:
12ww1160
2025-12-12 18:37:52 +01:00
parent a89e9442c7
commit e98fb543b7

88
Jenkinsfile vendored
View File

@@ -75,47 +75,61 @@ pipeline {
}
stage('Build Prometheus RPM') {
steps {
script {
def version = sh(
script: 'curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep \'"tag_name":\' | sed -E \'s/.*\\"([^\\"]+)\\".*/\\\\1/\' | sed \'s/v//\'',
returnStdout: true
).trim()
echo "Building Prometheus ${version}"
steps {
script {
// get tag_name from GitHub and strip leading "v"
def version = sh(
script: "curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | python -c 'import sys,json;print(json.load(sys.stdin)[\"tag_name\"].lstrip(\"v\"))'",
returnStdout: true
).trim()
def downloadUrl = "https://github.com/prometheus/prometheus/releases/download/v${version}/prometheus-${version}.linux-amd64.tar.gz"
sh "curl -L -o prometheus.tar.gz ${downloadUrl}"
sh 'tar xzf prometheus.tar.gz'
def extractDir = "prometheus-${version}.linux-amd64"
echo "Building Prometheus ${version}"
// Prepare build directory structure
sh """
mkdir -p build/prometheus/usr/bin build/prometheus/etc/prometheus build/prometheus/usr/share/prometheus
cp ${extractDir}/prometheus build/prometheus/usr/bin/
cp ${extractDir}/promtool build/prometheus/usr/bin/
cp ${extractDir}/prometheus.yml build/prometheus/etc/prometheus/
cp -r ${extractDir}/consoles build/prometheus/usr/share/prometheus/
cp -r ${extractDir}/console_libraries build/prometheus/usr/share/prometheus/
"""
def downloadUrl = "https://github.com/prometheus/prometheus/releases/download/v${version}/prometheus-${version}.linux-amd64.tar.gz"
echo "Downloading ${downloadUrl}"
sh """
fpm -s dir \\
-t rpm \\
-n prometheus \\
--version \${version} \\
--architecture x86_64 \\
--description 'Prometheus monitoring server and time series database' \\
--url 'https://prometheus.io' \\
--license 'Apache-2.0' \\
--vendor 'Prometheus Team' \\
--maintainer '12ww1160@confdroid.com' \\
-C build/prometheus \\
-f
"""
sh 'rm -rf build/prometheus prometheus.tar.gz ${extractDir}'
}
}
sh """
set -e
# download and extract
curl -fL -o prometheus.tar.gz "${downloadUrl}"
tar xzf prometheus.tar.gz
extractDir="prometheus-${version}.linux-amd64"
# prepare filesystem layout for fpm
rm -rf build/prometheus
mkdir -p build/prometheus/usr/bin build/prometheus/etc/prometheus build/prometheus/usr/share/prometheus
cp "\${extractDir}/prometheus" build/prometheus/usr/bin/
cp "\${extractDir}/promtool" build/prometheus/usr/bin/
# prometheus.yml may not exist in all releases (it usually does). ignore failure.
cp "\${extractDir}/prometheus.yml" build/prometheus/etc/prometheus/ || true
cp -r "\${extractDir}/consoles" build/prometheus/usr/share/prometheus/ || true
cp -r "\${extractDir}/console_libraries" build/prometheus/usr/share/prometheus/ || true
"""
// run fpm (note: ${version} is interpolated by Groovy into the shell)
sh """
fpm -s dir \
-t rpm \
-n prometheus \
--version ${version} \
--architecture x86_64 \
--description 'Prometheus monitoring server and time series database' \
--url 'https://prometheus.io' \
--license 'Apache-2.0' \
--vendor 'Prometheus Team' \
--maintainer '12ww1160@confdroid.com' \
-C build/prometheus \
-f
"""
// cleanup
sh "rm -rf build/prometheus prometheus.tar.gz prometheus-${version}.linux-amd64"
}
}
}
stage('update repo') {
steps {