Skip to content
Snippets Groups Projects
  • Maxim Cournoyer's avatar
    566bd6e8
    ci: Spread builds across multiple nodes. · 566bd6e8
    Maxim Cournoyer authored
    When a .tarball-version file containing the version string is present,
    it is taken for granted that the source tarball is present.  This
    allows to lift the requirement on a Git checkout to use the source
    tarball.  This makes it easy and cheap to sync this tarball and
    accompanying .tarball-version file across different Jenkins agents to
    distribute the packaging jobs, bring the total build time from about 1
    h 40 to 40 minutes.
    
    * Makefile (TARBALL_VERSION): New variable.  When defined, do not do
    not invoke Git to derive the version string, simply use it.
    [RELEASE_TARBALL_FILENAME]: Do not compute prerequisites when
    TARBALL_VERSION is defined; assume the tarball is present.
    * .gitignore: Ignore .tarball-version.
    * Jenkinsfile: (Generate release tarball): Generate a .tarball-version
    file, and stash it along the release tarball.  Explicit this should
    run on a 'guix' agent.
    (Build packages): Forward to any 'linux-builder' agent, clean the
    workspace, unstash and extract the tarball and build.
    
    GitLab: jami-packaging#98
    Change-Id: I13088b75c9ccd5166662a84b7c5f8d4e8b7b65da
    ci: Spread builds across multiple nodes.
    Maxim Cournoyer authored
    When a .tarball-version file containing the version string is present,
    it is taken for granted that the source tarball is present.  This
    allows to lift the requirement on a Git checkout to use the source
    tarball.  This makes it easy and cheap to sync this tarball and
    accompanying .tarball-version file across different Jenkins agents to
    distribute the packaging jobs, bring the total build time from about 1
    h 40 to 40 minutes.
    
    * Makefile (TARBALL_VERSION): New variable.  When defined, do not do
    not invoke Git to derive the version string, simply use it.
    [RELEASE_TARBALL_FILENAME]: Do not compute prerequisites when
    TARBALL_VERSION is defined; assume the tarball is present.
    * .gitignore: Ignore .tarball-version.
    * Jenkinsfile: (Generate release tarball): Generate a .tarball-version
    file, and stash it along the release tarball.  Explicit this should
    run on a 'guix' agent.
    (Build packages): Forward to any 'linux-builder' agent, clean the
    workspace, unstash and extract the tarball and build.
    
    GitLab: jami-packaging#98
    Change-Id: I13088b75c9ccd5166662a84b7c5f8d4e8b7b65da
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Jenkinsfile 3.76 KiB
// Packaging validation for supported GNU/Linux systems.
//
// Note: To work on this script without having to push a commit each
// time, use the jenkins-cli command (see:
// https://wiki.savoirfairelinux.com/wiki/Jenkins.jami.net#Usage_CLI_de_Jenkins).
pipeline {
    agent {
        label 'guix'
    }

    parameters {
        string(name: 'GERRIT_REFSPEC',
               defaultValue: 'refs/heads/master',
               description: 'The Gerrit refspec to fetch.')

        booleanParam(name: 'BUILD_OWN_QT',
                     defaultValue: false,
                     description: 'Whether to build our own Qt packages.')
        booleanParam(name: 'BUILD_ARM',
                     defaultValue: false,
                     description: 'Whether to build ARM packages.')
    }

    environment {
        TARBALLS = '/opt/ring-contrib' // set the cache directory
    }

    options {
        ansiColor('xterm')
    }

    stages {
        stage('Check configuration') {
            when { not { expression { fileExists TARBALLS } } }
            steps {
                error "The ${TARBALLS} directory does not exist. \
See https://wiki.savoirfairelinux.com/wiki/Jenkins.jami.net#Configuration"
            }
        }

        stage('Fetch submodules') {
            steps {
                echo 'Updating relevant submodules to their latest commit'
                sh 'git submodule update --init --recursive --remote ' +
                   'daemon lrc client-gnome client-qt'
            }
        }

        stage('Generate release tarball') {
            steps {
                // Note: sourcing .bashrc is necessary to setup the
                // environment variables used by Guix.
                sh '''#!/usr/bin/env bash
                   test -f $HOME/.bashrc && . $HOME/.bashrc
                   make portable-release-tarball .tarball-version
                   '''
                stash(includes: '*.tar.gz, .tarball-version',
                      name: 'release-tarball')
            }
        }

        stage('Build packages') {
            environment {
                DISABLE_CONTRIB_DOWNLOADS = 'TRUE'
                // The following password is used to register with the
                // RHEL subscription-manager tool, required to build on RHEL.
                PASS = credentials('developers-redhat-com')
            }
            steps {
                script {
                    def targetsText = sh(script: 'make -s list-package-targets',
                                         returnStdout: true)
                    def targets = targetsText.split('\n')
                    if (!params.BUILD_OWN_QT) {
                        targets = targets.findAll { !it.endsWith('_qt') }
                    }
                    if (!params.BUILD_ARM) {
                        targets = targets.findAll { !(it =~ /_(armhf|arm64)$/) }
                    }
                    def stages = [:]

                    targets.each { target ->
                        // Note: The stage calls are wrapped in closures, to
                        // delay their execution.
                        stages["${target}"] =  {
                            stage("${target}") {
                                // Offload builds to different agents.
                                node('linux-builder') {
                                    cleanWs()
                                    unstash 'release-tarball'
                                    sh """
                                       tar xf *.tar.gz --strip-components=1
                                       make ${target}
                                       """
                                }
                            }
                        }
                    }
                    parallel stages
                }
            }
        }
    }
}