Fix stepping in Jenkinsfile

This commit is contained in:
Gamerboy59 2024-09-10 23:05:53 +02:00 committed by GitHub
commit 8d87461f21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

64
.build/Jenkinsfile vendored
View file

@ -29,14 +29,10 @@ pipeline {
} }
steps { steps {
container('rust-cargo') { container('rust-cargo') {
// Step to install necessary tools // Install git
step('Install Git') {
sh 'apt-get update && apt-get -y install git --no-install-recommends' sh 'apt-get update && apt-get -y install git --no-install-recommends'
}
// Step to clone and prepare the repository // Clone and Prepare Repository
step('Clone and Prepare Repository') {
// Clone the repository
sh "git clone ${REPO_URL}" sh "git clone ${REPO_URL}"
dir('rust-rpxy') { dir('rust-rpxy') {
@ -47,40 +43,29 @@ pipeline {
# Initialize and update submodules # Initialize and update submodules
git submodule update --init git submodule update --init
""" """
}
}
// Step to extract BUILD_VERSION from Cargo.toml // Extract BUILD_VERSION from Cargo.toml
step('Extract BUILD_VERSION') {
script { script {
dir('rust-rpxy') {
// Extract version from Cargo.toml and set it as an environment variable // Extract version from Cargo.toml and set it as an environment variable
env.BUILD_VERSION = sh(script: "grep '^version' Cargo.toml | sed -E 's/version = \"(.+)\"/\\1/'", returnStdout: true).trim() env.BUILD_VERSION = sh(script: "grep '^version' Cargo.toml | sed -E 's/version = \"(.+)\"/\\1/'", returnStdout: true).trim()
echo "Using extracted version: ${env.BUILD_VERSION}" echo "Using extracted version: ${env.BUILD_VERSION}"
} }
}
}
// Step to build the binary // Build the binary
step('Compile Binary') {
dir('rust-rpxy') {
// Build the release version of the binary
sh 'cargo build --release' sh 'cargo build --release'
}
}
// Step to prepare and stash files // Prepare and stash files
step('Prepare and Stash Files') {
sh """ sh """
# Move binary to workspace root for easier access # Move binary to workspace root for easier access
mv rust-rpxy/target/release/${BINARY_NAME} . mv target/release/${BINARY_NAME} ..
# Move necessary files for packaging # Move necessary files for packaging
mv rust-rpxy/.build/DEB/{control,postinst,prerm,postrm} . mv .build/DEB/{control,postinst,prerm,postrm} ..
mv rust-rpxy/.build/RPM/${BINARY_NAME}.spec . mv .build/RPM/${BINARY_NAME}.spec ..
mv rust-rpxy/.build/{rpxy-start.sh,config.toml,rpxy.service} . mv .build/{rpxy-start.sh,config.toml,rpxy.service} ..
mv rust-rpxy/{LICENSE,README.md} . mv ./{LICENSE,README.md} ..
""" """
}
// Stash files for use in later stages // Stash files for use in later stages
stash includes: "${BINARY_NAME}", name: "binary" stash includes: "${BINARY_NAME}", name: "binary"
@ -94,7 +79,6 @@ pipeline {
} }
} }
} }
}
stage('Build RPM Package') { stage('Build RPM Package') {
agent { agent {
@ -115,9 +99,7 @@ pipeline {
} }
steps { steps {
container('rpm-build') { container('rpm-build') {
// Step to prepare the RPM build environment // Prepare the RPM build environment
step('Prepare RPM Build Environment') {
// Unstash necessary files
unstash 'binary' unstash 'binary'
unstash 'rpm-files' unstash 'rpm-files'
unstash 'service-file' unstash 'service-file'
@ -125,10 +107,8 @@ pipeline {
// Install necessary tools for RPM building // Install necessary tools for RPM building
sh 'dnf update -y && dnf install -y rpmdevtools tar' sh 'dnf update -y && dnf install -y rpmdevtools tar'
}
// Step to create the RPM package // Create the RPM package
step('Create RPM Package') {
sh """ sh """
# Create RPM build directory structure # Create RPM build directory structure
mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
@ -145,15 +125,12 @@ pipeline {
# Build the RPM package # Build the RPM package
rpmbuild --define "_topdir ${WORKSPACE}/rpmbuild" --define "_version ${BUILD_VERSION}" -bb rpmbuild/SPECS/${BINARY_NAME}.spec rpmbuild --define "_topdir ${WORKSPACE}/rpmbuild" --define "_version ${BUILD_VERSION}" -bb rpmbuild/SPECS/${BINARY_NAME}.spec
""" """
}
// Step to archive the RPM package // Archive the RPM package
step('Archive RPM Package') {
archiveArtifacts artifacts: "rpmbuild/RPMS/x86_64/${BINARY_NAME}-${BUILD_VERSION}-1.el9.x86_64.rpm", allowEmptyArchive: false, fingerprint: true archiveArtifacts artifacts: "rpmbuild/RPMS/x86_64/${BINARY_NAME}-${BUILD_VERSION}-1.el9.x86_64.rpm", allowEmptyArchive: false, fingerprint: true
} }
} }
} }
}
stage('Build DEB Package') { stage('Build DEB Package') {
agent { agent {
@ -174,9 +151,7 @@ pipeline {
} }
steps { steps {
container('debian-build') { container('debian-build') {
// Step to prepare the DEB build environment // Prepare the DEB build environment
step('Prepare DEB Build Environment') {
// Unstash necessary files
unstash 'binary' unstash 'binary'
unstash 'deb-files' unstash 'deb-files'
unstash 'service-file' unstash 'service-file'
@ -184,10 +159,8 @@ pipeline {
// Install necessary tools for DEB building // Install necessary tools for DEB building
sh 'apt-get update && apt-get install -y dpkg-dev --no-install-recommends' sh 'apt-get update && apt-get install -y dpkg-dev --no-install-recommends'
}
// Step to create the DEB package // Create the DEB package
step('Create DEB Package') {
sh """ sh """
# Define DEB package directory # Define DEB package directory
DEB_DIR=${BINARY_NAME}_${BUILD_VERSION}-1_amd64 DEB_DIR=${BINARY_NAME}_${BUILD_VERSION}-1_amd64
@ -212,14 +185,11 @@ pipeline {
# Build the DEB package # Build the DEB package
dpkg-deb --build --root-owner-group $DEB_DIR dpkg-deb --build --root-owner-group $DEB_DIR
""" """
}
// Step to archive the DEB package // Archive the DEB package
step('Archive DEB Package') {
archiveArtifacts artifacts: "${DEB_DIR}.deb", allowEmptyArchive: false, fingerprint: true archiveArtifacts artifacts: "${DEB_DIR}.deb", allowEmptyArchive: false, fingerprint: true
} }
} }
} }
} }
} }
}