Blob Blame History Raw
pipeline {
    agent none

    environment {
        AWS_REGION = "us-east-2"
    }

    options {
        ansiColor('xterm')
        timestamps()
    }

    stages {
        stage("Mock") {
            // Halt the entire pipeline if a single RPM build fails. That
            // could indicate a code problem that needs to be investigated.
            failFast true

            parallel {
                stage('Fedora 31') {
                    agent { label "fedora31" }
                    environment {
                        AWS_CREDS = credentials('aws-credentials-osbuildci')
                    }
                    steps {
                        sh "schutzbot/ci_details.sh"
                        sh "schutzbot/mockbuild.sh"
                        stash (
                            includes: 'osbuild-mock.repo',
                            name: 'fedora31'
                        )
                    }
                }
                stage('Fedora 32') {
                    agent { label "fedora32" }
                    environment {
                        AWS_CREDS = credentials('aws-credentials-osbuildci')
                    }
                    steps {
                        sh "schutzbot/ci_details.sh"
                        sh "schutzbot/mockbuild.sh"
                        stash (
                            includes: 'osbuild-mock.repo',
                            name: 'fedora32'
                        )
                    }
                }
                stage('RHEL 8 CDN') {
                    agent { label "rhel8" }
                    environment {
                        AWS_CREDS = credentials('aws-credentials-osbuildci')
                    }
                    steps {
                        sh "schutzbot/ci_details.sh"
                        sh "schutzbot/mockbuild.sh"
                        stash (
                            includes: 'osbuild-mock.repo',
                            name: 'rhel8cdn'
                        )
                    }
                }
                // NOTE(mhayden): Disabling this for now since we don't have
                // access to these repositories in AWS.
                // stage('RHEL 8.3 Nightly') {
                //     agent { label "rhel83" }
                //     environment {
                //         OPENSTACK_CREDS = credentials('psi-openstack-clouds-yaml')
                //     }
                //     steps {
                //         sh "schutzbot/mockbuild.sh"
                //         stash (
                //             includes: 'osbuild-mock.repo',
                //             name: 'rhel83'
                //         )
                //     }
                // }
            }
        }
        stage("Functional Testing") {
            // Allow the other stages to finish if a single stage fails.
            failFast false

            parallel {
                stage('Fedora 31') {
                    agent { label "fedora31 && psi" }
                    environment { TEST_TYPE = "image" }
                    steps {
                        unstash 'fedora31'
                        run_tests()
                    }
                    post {
                        always {
                            preserve_logs('fedora31-image')
                        }
                    }
                }
                stage('Fedora 32') {
                    agent { label "fedora32 && psi" }
                    environment { TEST_TYPE = "image" }
                    steps {
                        unstash 'fedora32'
                        run_tests()
                    }
                    post {
                        always {
                            preserve_logs('fedora32-image')
                        }
                    }
                }
                stage('RHEL 8 CDN') {
                    agent { label "rhel8 && psi" }
                    environment { TEST_TYPE = "image" }
                    steps {
                        unstash 'rhel8cdn'
                        run_tests()
                    }
                    post {
                        always {
                            preserve_logs('rhel8-image')
                        }
                    }
                }
            }
        }
    }
}

// Set up a function to hold the steps needed to run the tests so we don't
// need to copy/paste the same lines over and over above.
void run_tests() {

    // Get CI machine details.
    sh "schutzbot/ci_details.sh"

    // Run the tests from the repository.
    sh "schutzbot/run_tests.sh"

}

// Move logs to a unique location and tell Jenkins to capture them on success
// or failure.
void preserve_logs(test_slug) {

    // Make a directory for the log files and move the logs there.
    sh "mkdir ${test_slug} && mv *.log ${test_slug}/"

    // Artifact the logs.
    archiveArtifacts (
        allowEmptyArchive: true,
        artifacts: "${test_slug}/*.log"
    )

}