summaryrefslogtreecommitdiff
path: root/Jenkinsfile
blob: af7968e71ead29e633b7e4c94a5b282a9e3d21a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env groovy

// The stages we run one by one
// Please don't add more than 2 items in a single stage; this hurts performance
def ci_stages = [
    "Checkers": [
        "commit-checker": "openttd/compile-farm-ci:commit-checker",
    ],
    "Compilers": [
        "linux-amd64-gcc-6": "openttd/compile-farm-ci:linux-amd64-gcc-6",
        "linux-amd64-clang-3.8": "openttd/compile-farm-ci:linux-amd64-clang-3.8",
    ],
    "Archs": [
        "linux-i386-gcc-6": "openttd/compile-farm-ci:linux-i386-gcc-6",
    ],
    "OS": [
        "osx-10.9": "openttd/compile-farm-ci:osx-10.9",
    ],
]

def generateStage(targets) {
    return targets.collectEntries{ key, target ->
        ["${key}": generateCI(key, target)]
    }
}

def generateCI(display_name, image_name) {
    return {
        githubNotify context: 'openttd/' + display_name, description: 'This commit is being built', status: 'PENDING'

        try {
            dir("${display_name}") {
                unstash "source"

                docker.image("${image_name}").pull()
                docker.image("${image_name}").withRun("--volumes-from ${hostname} --workdir " + pwd()) { c ->
                    sh "docker logs --follow ${c.id}; exit `docker wait ${c.id}`"
                }
            }

            githubNotify context: 'openttd/' + display_name, description: 'The commit looks good', status: 'SUCCESS'
        }
        catch (error) {
            githubNotify context: 'openttd/' + display_name, description: 'The commit cannot be built', status: 'FAILURE'
            throw error
        }
    }
}

node {
    ansiColor('xterm') {
        stage("Checkout") {
            checkout scm

            // Ensure user.email and user.name is set, otherwise rebase cannot work
            sh "git config user.email 'info@openttd.org'"
            sh "git config user.name 'OpenTTD CI'"

            // Ensure we also have origin/master available
            sh "git fetch --no-tags origin master:refs/remotes/origin/master"

            // Try to rebase to origin/master; if this fails, fail the CI
            sh "git rebase origin/master"

            stash name: "source", useDefaultExcludes: false
        }

        ci_stages.each { ci_stage ->
            stage(ci_stage.key) {
                parallel generateStage(ci_stage.value)
            }
        }
    }
}