Util.groovy 2.34 KB
Newer Older
Andrew Nicols's avatar
Andrew Nicols committed
1 2
package org.moodle.ci;

Andrew Nicols's avatar
meh  
Andrew Nicols committed
3 4 5
def getDefaultRunCombinations(branch) {
    def php = branch.getPhpVersions()
    def db = branch.getDatabases()
Andrew Nicols's avatar
Andrew Nicols committed
6 7 8
    def combinations = [:]

    for (int i = 0; i < db.size(); i++) {
Andrew Nicols's avatar
Andrew Nicols committed
9 10 11 12
        combinations[i] = [
            "db":   db[i],
            "php":  php[php.size() - 1]
        ]
Andrew Nicols's avatar
Andrew Nicols committed
13 14 15 16 17
    }

    return combinations;
}

Andrew Nicols's avatar
wip  
Andrew Nicols committed
18 19 20 21 22 23 24 25 26
def getHighestSupportedVersion(branch) {
    return branch[branch.size() - 1]
}

def getLowestSupportedVersion(branch) {
    return branch[0]
}

def runTask(
Andrew Nicols's avatar
Andrew Nicols committed
27
  String task,
Andrew Nicols's avatar
Andrew Nicols committed
28
  String repo,
Andrew Nicols's avatar
Andrew Nicols committed
29
  String branch,
Andrew Nicols's avatar
wip  
Andrew Nicols committed
30 31
  String phpversion,
  String database,
Andrew Nicols's avatar
Andrew Nicols committed
32 33
  Boolean notify,
  Boolean publish
Andrew Nicols's avatar
Andrew Nicols committed
34 35
  ) {

Andrew Nicols's avatar
wip  
Andrew Nicols committed
36 37
    node('docker') {
        stage("Git Checkout") {
Andrew Nicols's avatar
Andrew Nicols committed
38
            echo "Starting ${task} on ${phpversion}/${database} from {$repo} ${branch}"
Andrew Nicols's avatar
Andrew Nicols committed
39

Andrew Nicols's avatar
wip  
Andrew Nicols committed
40 41 42 43
            checkout(
                [
                    $class: 'GitSCM',
                    branches: [
Andrew Nicols's avatar
Andrew Nicols committed
44
                        [
Andrew Nicols's avatar
Andrew Nicols committed
45
                            name: "${branch}"
Andrew Nicols's avatar
Andrew Nicols committed
46
                        ]
Andrew Nicols's avatar
wip  
Andrew Nicols committed
47 48 49 50 51 52 53
                    ],
                    doGenerateSubmoduleConfigurations: false,
                    extensions: [
                        [
                            $class: 'CloneOption',
                            depth: 0,
                            noTags: false,
Andrew Nicols's avatar
Andrew Nicols committed
54
                            reference: "${env.HOME}/caches/integration.git",
Andrew Nicols's avatar
wip  
Andrew Nicols committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
                            shallow: false
                        ],
                        [
                            $class: 'RelativeTargetDirectory',
                            relativeTargetDir: 'moodle'
                        ]
                    ],
                    submoduleCfg: [],
                    userRemoteConfigs: [
                        [
                            url: "${repo}"
                        ]
                    ]
                ]
            )
        }
Andrew Nicols's avatar
Andrew Nicols committed
71

Andrew Nicols's avatar
wip  
Andrew Nicols committed
72 73 74 75 76 77 78
        stage("Run ${task}") {
            withEnv([
                "PHP_VERSION=${phpversion}",
                "DBTYPE=${database}",
                "TASK=${task}"
            ]) {
                sh '$HOME/scripts/runner/master/run.sh'
Andrew Nicols's avatar
Andrew Nicols committed
79 80 81
            }
        }

Andrew Nicols's avatar
wip  
Andrew Nicols committed
82 83 84 85 86 87
        stage("Post") {
            junit allowEmptyResults: true, testResults: '$BUILD_ID/*.junit/*.xml,$BUILD_ID/*.junit'
            archiveArtifacts allowEmptyArchive: true, artifacts: '$BUILD_ID/**'
            cleanWs deleteDirs: true, notFailBuild: true
        }
    }
Andrew Nicols's avatar
Andrew Nicols committed
88 89 90 91
}


return this;