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') { stage('Build Prometheus RPM') {
steps { steps {
script { script {
def version = sh( // get tag_name from GitHub and strip leading "v"
script: 'curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep \'"tag_name":\' | sed -E \'s/.*\\"([^\\"]+)\\".*/\\\\1/\' | sed \'s/v//\'', def version = sh(
returnStdout: true 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\"))'",
).trim() returnStdout: true
echo "Building Prometheus ${version}" ).trim()
def downloadUrl = "https://github.com/prometheus/prometheus/releases/download/v${version}/prometheus-${version}.linux-amd64.tar.gz" echo "Building Prometheus ${version}"
sh "curl -L -o prometheus.tar.gz ${downloadUrl}"
sh 'tar xzf prometheus.tar.gz'
def extractDir = "prometheus-${version}.linux-amd64"
// Prepare build directory structure def downloadUrl = "https://github.com/prometheus/prometheus/releases/download/v${version}/prometheus-${version}.linux-amd64.tar.gz"
sh """ echo "Downloading ${downloadUrl}"
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/
"""
sh """ sh """
fpm -s dir \\ set -e
-t rpm \\ # download and extract
-n prometheus \\ curl -fL -o prometheus.tar.gz "${downloadUrl}"
--version \${version} \\ tar xzf prometheus.tar.gz
--architecture x86_64 \\
--description 'Prometheus monitoring server and time series database' \\ extractDir="prometheus-${version}.linux-amd64"
--url 'https://prometheus.io' \\
--license 'Apache-2.0' \\ # prepare filesystem layout for fpm
--vendor 'Prometheus Team' \\ rm -rf build/prometheus
--maintainer '12ww1160@confdroid.com' \\ mkdir -p build/prometheus/usr/bin build/prometheus/etc/prometheus build/prometheus/usr/share/prometheus
-C build/prometheus \\
-f cp "\${extractDir}/prometheus" build/prometheus/usr/bin/
""" cp "\${extractDir}/promtool" build/prometheus/usr/bin/
sh 'rm -rf build/prometheus prometheus.tar.gz ${extractDir}' # 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') { stage('update repo') {
steps { steps {