#!/usr/bin/env groovy def RPMSource() { dir ('source') { checkout([ $class: 'GitSCM', branches: [ [ name: '*/master' ] ], extensions: [ [ $class: 'CloneOption', timeout: 60 ] ], userRemoteConfigs: [ [ url: 'git://git.kraxel.org/mirror/ipxe.git' ] ]]) } } def RPMBuild() { sh ''' # cleanup rm -rf "${WORKSPACE}/rpms" "${WORKSPACE}/build" "${WORKSPACE}/buildroot" # figure version commit="$(cd source; git describe --tags --long --match 'v*')" ghash="${commit##*-}" commit="${commit%-*}" gcnt="${commit##*-}" commit="${commit%-*}" version="${commit#v}" # fresh snapshot tarball rm -f *.tar.gz tarball="ipxe-${ghash}.tar.gz" (cd source; git archive --format=tar --prefix="${tarball%.tar.gz}/" HEAD) \ | gzip > "${tarball}" # tweak spec file sed -i.orig \ -e "s/\\(Version:[ \\t]\\+\\)\\(.*\\)/\\1${version}/" \ -e "s/\\(Release:[ \\t]\\+\\)\\(.*\\)/\\1${gcnt}.${BUILD_NUMBER}.${ghash}/" \ -e "s/\\(Source0:[ \\t]\\+\\)\\(.*\\)/\\1${tarball}/" \ -e "s/\\(%setup\\)\\(.*\\)/\\1 -n ${tarball%.tar.gz}/" \ *.spec diff -u *.spec.orig *.spec || true # install deps /usr/local/bin/configure-mirror yum-builddep -y *.spec # build package rpmbuild \ --define "_specdir ${WORKSPACE}" \ --define "_sourcedir ${WORKSPACE}" \ --define "_rpmdir ${WORKSPACE}/rpms" \ --define "_srcrpmdir ${WORKSPACE}/rpms/src" \ --define "_builddir ${WORKSPACE}/build" \ --define "_buildrootdir ${WORKSPACE}/buildroot" \ -ba *.spec # revert spec file tweaks git reset --hard # drop source rpm rm -rf "${WORKSPACE}/rpms/src" # create rpm package repo createrepo_c rpms ''' archiveArtifacts 'rpms/*/*' } pipeline { agent { docker { image 'registry.gitlab.com/kraxel/rpm-package-builder:centos7' args '-u root' } } options { buildDiscarder(logRotator(numToKeepStr: '5')) disableConcurrentBuilds() } triggers { pollSCM('H * * * *') } stages { stage ('Prepare') { steps { RPMSource(); } } stage ("RPM Build") { steps { RPMBuild() } } } post { failure { emailext([ to: 'builds@kraxel.org', subject: "${JOB_NAME} - build #${BUILD_NUMBER} - FAILED!", body: "${BUILD_URL}\n", attachLog: true, ]) } } }