def getFedoraVersions() { def response = httpRequest( url: 'https://bodhi.fedoraporject.org/releases?state=current', acceptType: 'APPLICATION_JSON', ) def content = readJSON(text: response.content) return content.releases. findAll { it.id_prefix == "FEDORA" }. collect { it.version } } def matrixBuild(architectures, fedoraVersions, block) { echo "Building for Fedora ${fedoraVersions}, architectures ${architectures}" parallel architectures.collectMany { arch -> fedoraVersions.collect { version -> [arch, version] } }.collectEntries { def arch = it[0] def version = it[1] ["f${version}/${arch}", { block(arch, version) }] } } def podTemplateYaml = readTrusted('ci/podTemplate.yaml') def architectures = ["amd64"] def fedoraVersions = getFedoraVersions() stage('Fetch Sources') { podTemplate( yaml: podTemplateYaml, yamlMergeStrategy: merge(), ) { node(POD_LABEL) { checkout scm def version container('build') { version = sh( script: '''rpmspec -q --srpm --qf '%{VERSION}' wal-g.spec''', returnStdout: true, ) } container('fetch') { sh "sh sources.sh ${version}" } stash name: 'sources', includes: 'wal-g-*.tar.gz' } } } matrixBuild(architectures, fedoraVersions) { arch, fedoraVersion -> def tmpl = readYaml(text: podTemplateYaml) tmpl.spec.containers.each { container -> if (container.name == 'build') { container.image = "registry.fedoraproject.org/fedora:${fedoraVersion}" } } podTemplate( yaml: writeYaml(data: tmpl, returnText: true), yamlMergeStrategy: merge(), nodeSelector: "kubernetes.io/arch=${arch}", ) { node(POD_LABEL) { checkout scm stage("Prepare f${fedoraVersion}/${arch}") { container('build') { sh '. ci/prepare.sh' } } stage("Build f${fedoraVersion}/${arch}") { unstash 'sources' container('build') { sh '. ci/build.sh' } } stage("Sign f${fedoraVersion}/${arch}") { when(env.BRANCH_NAME == 'master') { container('build') { withCredentials([ file( credentialsId: 'rpm-gpg-key', variable: 'RPM_GPG_PRIVATE_KEY', ), file( credentialsId: 'rpm-gpg-key-passphrase', variable: 'RPM_GPG_KEY_PASSPHRASE', ), ]) { sh '. ci/sign-rpms.sh' } } } } archiveArtifacts '*.rpm' stage("Publish f${fedoraVersion}/${arch}") { when(env.BRANCH_NAME == 'master') { container('build') { sshagent(['jenkins-repohost']) { sh '. ci/publish.sh' } } } } } } }