aboutsummaryrefslogtreecommitdiff
path: root/jenkins/test-runner.jpl
blob: 19daff29577d2c798ed1735755ef3274d1fa292e (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env groovy

/*
  Copyright (C) 2019 Collabora Limited
  Author: Guillaume Tucker <guillaume.tucker@collabora.com>

  This module is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by the Free
  Software Foundation; either version 2.1 of the License, or (at your option)
  any later version.

  This library is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
  details.

  You should have received a copy of the GNU Lesser General Public License
  along with this library; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

/* ----------------------------------------------------------------------------
 * Jenkins parameters

LABS
  Name of the labs where to submit tests
TRIGGER_JOB_NAME
  Name of the parent trigger job
TRIGGER_JOB_NUMBER
  Number of the parent trigger job
BUILD_JOB_NAME
  Name of the job that built the kernel
BUILD_JOB_NUMBER
  Number of the job that built the kernel
KCI_CORE_URL (https://github.com/kernelci/kernelci-core.git)
  URL of the kernelci-core repository
KCI_CORE_BRANCH (master)
  Name of the branch to use in the kernelci-core repository
KCI_STORAGE_URL (https://storage.kernelci.org/)
  URL of the KernelCI storage server
DOCKER_BASE (kernelci/build-)
  Dockerhub base address used for the build images
CALLBACK_ID (kernel-ci-callback)
  Identifier of the callback to look up an authentication token
CALLBACK_URL (https://api.kernelci.org)
  Base URL where to send the callbacks
*/

@Library('kernelci') _
import org.kernelci.util.Job

def getArtifacts(artifacts)
{
    dir(artifacts) {
        copyArtifacts(
            projectName: params.BUILD_JOB_NAME,
            selector: specific("${params.BUILD_JOB_NUMBER}")
        )

        if (params.TRIGGER_JOB_NAME) {
            copyArtifacts(
                projectName: params.TRIGGER_JOB_NAME,
                selector: specific("${params.TRIGGER_JOB_NUMBER}")
            )
        }
    }
}

def generateJobs(kci_core, lab, artifacts, jobs_dir)
{
    def token = "${lab}-lava-api"

    dir(kci_core) {
        withCredentials([string(credentialsId: token, variable: 'SECRET')]) {
            sh(script: """\
./kci_test \
generate \
--bmeta-json=${artifacts}/bmeta.json \
--dtbs-json=${artifacts}/dtbs.json \
--lab-json=${artifacts}/${lab}.json \
--storage=${params.KCI_STORAGE_URL} \
--lab=${lab} \
--user=kernel-ci \
--token=${SECRET} \
--output=${jobs_dir} \
--callback-id=${params.CALLBACK_ID} \
--callback-url=${params.CALLBACK_URL} \
""")
        }
    }
}

def submitJobs(kci_core, lab, jobs_dir)
{
    def token = "${lab}-lava-api"

    dir(kci_core) {
        withCredentials([string(credentialsId: token, variable: 'SECRET')]) {
            sh(script: """\
./kci_test \
submit \
--lab=${lab} \
--user=kernel-ci \
--token=${SECRET} \
--jobs=${jobs_dir}/* \
""")
        }
    }
}

node("docker && test-runner") {
    def j = new Job()
    def kci_core = "${env.WORKSPACE}/kernelci-core"
    def jobs_dir = "${env.WORKSPACE}/jobs"
    def artifacts = "${env.WORKSPACE}/artifacts"
    def docker_image = "${params.DOCKER_BASE}base"
    def labs = params.LABS.tokenize(' ')
    def labs_submit = []

    print("""\
    Labs:      ${params.LABS}
    Container: ${docker_image}""")

    j.dockerPullWithRetry(docker_image).inside() {
        stage("Init") {
            sh(script: "rm -rf ${artifacts}")
            sh(script: "rm -rf ${jobs_dir}")

            timeout(time: 15, unit: 'MINUTES') {
                parallel(
                    kci_core: {
                        j.cloneKciCore(
                            kci_core,
                            params.KCI_CORE_URL, params.KCI_CORE_BRANCH)
                    },
                    artifacts: {
                        getArtifacts(artifacts)
                    },
                )
            }

            print("Artifacts:")
            sh(script: "ls -l ${artifacts}")

            print("Build meta-data:")
            sh(script: "cat ${artifacts}/bmeta.json")
        }

        stage("Generate") {
            for (lab in labs) {
                def lab_dir = "${jobs_dir}/${lab}"
                generateJobs(kci_core, lab, artifacts, lab_dir)
                labs_submit.add(lab)
            }
        }

        stage("Submit") {
            def steps = [:]
            def i = 0

            for (lab in labs_submit) {
                def lab_name = "${lab}"
                def lab_dir = "${jobs_dir}/${lab}"
                def step_name = "${i} ${lab}"

                print(step_name)

                steps[step_name] = {
                    submitJobs(kci_core, lab_name, lab_dir)
                }

                i += 1
            }

            parallel(steps)
        }
    }
}