Commit dafa8961 authored by acpaquette's avatar acpaquette Committed by Kelvin Rodriguez
Browse files

Jenkins Changes (#3557)

* Jenkins file update to make use of the web hook

* Added a groovy utilities file

* Changed the pipeline to load the right file

* Updated the name of the groovy file

* Removed unnecessary isis app -help commands
parent faf0ac0b
Loading
Loading
Loading
Loading
+197 −34
Original line number Diff line number Diff line
@@ -3,42 +3,205 @@
pipeline
{
    agent any
    stages
    {
        stage('CI')
        {
            parallel
            {
                stage('Mac')
                {
                    agent{ label 'mac'}

    stages {
        stage ("CI") {
            steps {
                        build 'ISIS-Builds/Mac'
                script {
                    def groovy_utilities = load "${pwd()}/groovy_utilities.groovy"

                    def isisDataPath = '/isisData/data'

                    def isisMgrScripts = '/isisData/data/isis3mgr_scripts'

                    def isisTestDataPath = "/isisData/testData"

                    def kakaduIncDir = "/isisData/kakadu"

                    def isisEnv = [
                        "ISIS3DATA=${isisDataPath}",
                        "ISIS3TESTDATA=${isisTestDataPath}",
                        "ISIS3MGRSCRIPTS=${isisMgrScripts}"
                    ]

                    def cmakeFlags = [
                        "-DJP2KFLAG=ON",
                        "-DKAKADU_INCLUDE_DIR=${kakaduIncDir}",
                        "-Dpybindings=OFF",
                        "-DCMAKE_BUILD_TYPE=RELEASE"
                    ]

                    def build_ok = true
                    def errors = []

                    def labels = ['CentOS', 'Fedora', 'Ubuntu'] // labels for Jenkins node types we will build on
                    def builders = [:]

                    for (x in labels) {
                        def label = x // Need to bind the label variable before the closure - can't do 'for (label in labels)'
                        def lower_label = x.toLowerCase()

                        // Create a map to pass in to the 'parallel' step so we can fire all the builds at once
                        builders[lower_label] = {
                            node(lower_label) {
                                stage ("${label}") {

                                    env.STAGE_STATUS = "Checking out ISIS"
                                    checkout scm
                                    isisEnv.add("ISISROOT=${pwd()}/build")
                                    cmakeFlags.add("-DCMAKE_INSTALL_PREFIX=${pwd()}/install")

                                    env.STAGE_STATUS = "Creating conda environment"
                                    sh '''
                                      # Use the conda cache running on the Jenkins host
                                      conda config --set channel_alias http://dmz-jenkins.wr.usgs.gov
                                      conda config --set always_yes True
                                      conda create -n isis python=3
                                    '''

                                    if (lower_label == "centos") {
                                      sh 'conda env update -n isis -f environment_gcc4.yml --prune'
                                    } else {
                                      sh 'conda env update -n isis -f environment.yml --prune'
                                    }

                                    withEnv(isisEnv) {
                                        dir("${env.ISISROOT}") {
                                            try {
                                                env.STAGE_STATUS = "Building ISIS on ${label}"
                                                sh """
                                                    source activate isis
                                                    cmake -GNinja ${cmakeFlags.join(' ')} ../isis
                                                    ninja -j4 install
                                                    python ../isis/scripts/isis3VarInit.py --data-dir ${env.ISIS3DATA} --test-dir ${env.ISIS3TESTDATA}
                                                """
                                            }
                stage('CentOS')
                {
                    steps
                    {
                        build 'ISIS-Builds/CentOS'
                                            catch(e) {
                                                build_ok = false
                                                errors.add(env.STAGE_STATUS)
                                                println e.toString()
                                            }
                                        }
                stage('Fedora')
                {
                    steps
                    {
                        build 'ISIS-Builds/Fedora'

                                        if (build_ok) {
                                            dir("${env.ISISROOT}") {
                                                try  {
                                                    env.STAGE_STATUS = "Running unit tests on ${env.OS}"
                                                        sh """
                                                            source activate isis
                                                            echo $ISIS3TESTDATA
                                                            echo $ISIS3DATA

                                                            # environment variables
                                                            export ISISROOT=${env.ISISROOT}
                                                            export ISIS3TESTDATA="/isisData/testData"
                                                            export ISIS3DATA="/isisData/data"
                                                            export PATH=`pwd`/../install/bin:/home/jenkins/.conda/envs/isis/bin:$PATH

                                                            ctest -R _unit_ -j4 -VV
                                                        """
                                                }
                                                catch(e) {
                                                    build_ok = false
                                                    echo e.toString()
                                                }
                stage('Ubuntu')
                {
                    steps
                    {
                        build 'ISIS-Builds/Ubuntu'

                                                try{
                                                    env.STAGE_STATUS = "Running app tests on ${env.OS}"
                                                    sh """
                                                        source activate isis
                                                        echo $ISIS3TESTDATA
                                                        echo $ISIS3DATA
                                                        echo $PATH

                                                        # environment variables
                                                        export ISISROOT=${env.ISISROOT}
                                                        export ISIS3TESTDATA="/isisData/testData"
                                                        export ISIS3DATA='/isisData/data'
                                                        export PATH=`pwd`/../install/bin:/home/jenkins/.conda/envs/isis/bin:$PATH

                                                        ctest -R _app_ -j4 -VV
                                                        source deactivate

                                                    """
                                                }
                                                catch(e) {
                                                    build_ok = false
                                                    errors.add(env.STAGE_STATUS)
                                                    println e.toString()
                                                }

                                                try{
                                                    env.STAGE_STATUS = "Running module tests on ${env.OS}"
                                                    sh """
                                                        source activate isis
                                                        echo $ISIS3TESTDATA
                                                        echo $ISIS3DATA
                                                        echo $PATH

                                                        # environment variables
                                                        export ISISROOT=${env.ISISROOT}
                                                        export ISIS3TESTDATA="/isisData/testData"
                                                        export ISIS3DATA='/isisData/data'
                                                        export PATH=`pwd`/../install/bin:/home/jenkins/.conda/envs/isis/bin:$PATH

                                                        ctest -R _module_ -j4 -VV
                                                        source deactivate

                                                    """
                                                }
                                                catch(e) {
                                                    build_ok = false
                                                    errors.add(env.STAGE_STATUS)
                                                    println e.toString()
                                                }

                                                try{
                                                    env.STAGE_STATUS = "Running gtests on ${env.OS}"
                                                    sh """
                                                        source activate isis
                                                        echo $ISIS3TESTDATA
                                                        echo $ISIS3DATA
                                                        echo $PATH

                                                        # environment variables
                                                        export ISISROOT=${env.ISISROOT}
                                                        export ISIS3TESTDATA="/isisData/testData"
                                                        export ISIS3DATA='/isisData/data'
                                                        export PATH=`pwd`/../install/bin:/home/jenkins/.conda/envs/isis/bin:$PATH

                                                        ctest -R "." -E "(_app_|_unit_|_module_)" -j4 -VV
                                                        source deactivate

                                                    """
                                                }
                                                catch(e) {
                                                    build_ok = false
                                                    errors.add(env.STAGE_STATUS)
                                                    println e.toString()
                                                }
                                            }
                                        }

                                        if(build_ok) {
                                            currentBuild.result = "SUCCESS"
                                        }
                                        else {
                                            currentBuild.result = "FAILURE"
                                            def comment = "Failed during:\n"
                                            errors.each {
                                                comment += "- ${it}\n"
                                            }
                                            groovy_utilities.setGitHubBuildStatus(comment)
                                        }
                                    }
                                }
                            }
                        }
                    }
                    parallel builders
                }
            }
        }
    }
}
+32 −0
Original line number Diff line number Diff line
// vim: ft=groovy

// Helpers for setting commit status
def getRepoUrl() {
    return sh(script: "git config --get remote.origin.url", returnStdout: true).trim()
}

def getCommitSha() {
    return sh(script: "git rev-parse HEAD", returnStdout: true).trim()
}

def setGitHubBuildStatus(status) {
    def repoUrl = getRepoUrl()
    def commitSha = getCommitSha()

    step([
        $class: 'GitHubCommitStatusSetter',
        reposSource: [$class: "ManuallyEnteredRepositorySource", url: repoUrl],
        commitShaSource: [$class: "ManuallyEnteredShaSource", sha: commitSha],
        errorHandlers: [[$class: 'ShallowAnyErrorHandler']],
        statusResultSource: [
          $class: 'ConditionalStatusResultSource',
          results: [
            [$class: 'BetterThanOrEqualBuildResult', result: 'SUCCESS', state: 'SUCCESS', message: status],
            [$class: 'BetterThanOrEqualBuildResult', result: 'FAILURE', state: 'FAILURE', message: status],
            [$class: 'AnyBuildResult', state: 'FAILURE', message: 'Loophole']
          ]
        ]
    ])
}

return this