Debian Codegraph @

scripts/ci/Jenkinsfile

raw
1 // Initialize a variable to hold the matrix of travis builds
2 tmatrix = []
3
4 /* This function takes a list of tests and builds closures for each test to
5 * be run in it's own docker container. It's a little strange, and uses a
6 * functional programming trick (function currying) to create a closure that
7 * can be passed to the "parallel" function, which can only take one argument
8 * in this context
9 */
10
11 def buildClosures(arg) {
12 println arg.inspect()
13 def travisTests = arg
14 def closures = [:]
15 for (value in travisTests) {
16 final valueCopy = value
17 closures[value] = { testEnv_str ->
18 def(dir,testEnv) = testEnv_str.split(":")
19 stage("$testEnv") {
20 // Docker needs full privileges and capabilites to run the tests
21 // This passes the necessary arguments to "docker run"
22 travisImage.inside("--privileged --cap-add=ALL") {
23 checkout([$class: 'GitSCM',\
24 branches: [[name: scm.branches[0].name]],\
25 doGenerateSubmoduleConfigurations: false,\
26 extensions: [[$class: 'CleanCheckout'],\
27 [$class: 'CleanBeforeCheckout'],\
28 [$class: 'RelativeTargetDirectory', relativeTargetDir: dir]],\
29 submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/FreeRADIUS/freeradius-server']]])
30 sh "cd $dir ; export ${testEnv} ; bash scripts/travis/start.sh"
31 }
32 }
33 }.curry(value)
34 }
35 closures
36 }
37
38 /* This section does three things
39 * 1. Checkout the repo for the necessary setup files
40 * 2. Reads the test matrix from the .travis.yml and converts it into a list that
41 * can be passed to the buildClosures function
42 * 3. runs each test matrix under gcc and clang in parallel.
43 */
44
45 node {
46 cleanWs()
47 checkout scm
48 travis = readYaml(file: "./.travis.yml")
49 travisImage = docker.build("travis-image-${scm.branches[0].name}", "./scripts/travis/")
50 stage("clang tests") {
51 tmatrix = []
52 c = "clang"
53 travis["env"]["matrix"].eachWithIndex { t,i ->
54 tmatrix << "${c}-${i}:CC=${c} ${t}"
55 }
56 parallel buildClosures(tmatrix)
57 }
58 stage("gcc tests") {
59 tmatrix = []
60 c = "gcc"
61 travis["env"]["matrix"].eachWithIndex { t,i ->
62 tmatrix << "${c}-${i}:CC=${c} ${t}"
63 }
64 parallel buildClosures(tmatrix)
65 }
66 }