aboutsummaryrefslogtreecommitdiff
path: root/milo-kbuilder.yaml
blob: 7c0052cb02f875fceffd848174bad62ebaafe017 (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
- job:
    name: milo-kbuilder
    project-type: matrix
    defaults: global
    parameters:
        - string:
            name: ARCH_LIST
            default: 'arm'
        - string:
            name: DEFCONFIG_LIST
            default: 'defconfig'
        - string:
            name: TREE
            default: 'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git'
        - string:
            name: BRANCH
            default: 'master'
        - string:
            name: COMMIT_ID
            default: ''
        - string:
            name: TREE_NAME
            default: 'milo-test'
        - bool:
            name: PUBLISH
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            khilman@kernel.org:
                - job-read
                - job-extended-read
                - job-build
                - job-cancel
            milo.casagrande@linaro.org:
                - job-read
                - job-extended-read
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 3
            num-to-keep: 5
        - throttle:
            max-total: 6
            option: project
        - inject
    disabled: false
    node: x86_64
    retry-count: 3
    child-workspace: .
    display-name: 'milo - kbuilder'
    auth-token: ${AUTH_TOKEN}
    axes:
        - axis:
            type: slave
            name: label
            values:
                - kernel_build_vps
        - axis:
            type: dynamic
            name: arch
            values:
                - ARCH_LIST
        - axis:
            type: dynamic
            name: defconfig
            values:
                - DEFCONFIG_LIST
    wrappers:
        - timestamps
        - matrix-tie-parent:
            node: x86_64
        - timeout:
            timeout: 45
    builders:
        - shell: |
            #!/bin/bash

            set -x

            # local copy of build scripts
            if [ ! -d local ]; then
              mkdir -p local
              (cd local; git clone --depth=1 https://github.com/MiloCasagrande/kernelci-build.git)
            fi

            (cd local/kernelci-build; git pull)
            export PATH=${WORKSPACE}/local/kernelci-build:${PATH}

            # Ensure TREE URL is decoded
            TREE=`python -c "import urllib, sys; print urllib.unquote(sys.argv[1])" ${TREE}`
            BRANCH=`python -c "import urllib, sys; print urllib.unquote(sys.argv[1])" ${BRANCH}`

            #
            # Kernel tree -- clone Linus' tree and add ${TREE} as remote.  This takes advantage
            # of all the tags in Linus' tree for more useful git-describe output.
            #
            MIRROR=/srv/mirrors/linux.git
            REFSPEC=+refs/heads/${BRANCH}:refs/remotes/origin/${BRANCH}
            if [ -e ${TREE_NAME} ]; then
                cd ${TREE_NAME} && \
                timeout --preserve-status -k 10s 5m git fetch --tags linus && \
                timeout --preserve-status -k 10s 5m git fetch --tags ${TREE} ${REFSPEC}
            else
              git clone -o linus --reference ${MIRROR} https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ${TREE_NAME}
              cd ${TREE_NAME} && \
              git remote add origin ${TREE} && \
              timeout --preserve-status -k 10s 5m git fetch origin
            #   (cd ${TREE_NAME}; git remote add origin ${TREE}; git fetch origin ${REFSPEC})
            fi
            if [ $? != 0 ]; then
              exit 1
            fi

            cd ${TREE_NAME}
            #rm -rf _install_
            git clean -df
            timeout --preserve-status -k 10s 5m git fetch origin ${REFSPEC}
            if [ $? != 0 ]; then
              exit 1
            fi
            if [ -z ${COMMIT_ID} ]; then
              git checkout -f origin/${BRANCH}
            else
              git checkout -f origin/${BRANCH}
              git branch -D local/${BRANCH}
              git checkout -b local/${BRANCH} -f ${COMMIT_ID}
            fi
            if [ $? != 0 ]; then
              exit 1
            fi

            # Ensure abbrev SHA1s are 12 chars
            git config --global core.abbrev 12

            # Only use v3.x tags in arm-soc tree
            unset describe_args
            [ ${TREE_NAME} = "arm-soc" ] && describe_args="--match=v\*"
            GIT_DESCRIBE=$(eval git describe $describe_args)
            GIT_DESCRIBE=${GIT_DESCRIBE//\//_}  # replace any '/' with '_'
            echo GIT_DESCRIBE=${GIT_DESCRIBE} > env.properties

            #export CCACHE_DISABLE=true

            # Convert defconfig of form "foo+bar" into "foo -c bar"
            defconfig_translated=`echo ${defconfig} | sed 's/\+/ \-c /g'`

            # Build kernel/modules and install (default: ./_install_ dir)
            export LANG=C
            export ARCH=${arch}
            if [ $PUBLISH != true ]; then
                buildv2.py -i -q -d -c ${defconfig_translated}
            else
                buildv2.py -i -q -d -p production -c ${defconfig_translated}
            fi
            RC=$?

            # Remove the build output (important stuff in _install_ dir)
            rm -rf build

            echo "Kernel build result: ${RC}"
            echo ${RC} > build.result

            # Always return success here so pass/fail results can still be published
            exit 0

        - inject:
            properties-file: ${TREE_NAME}/env.properties

        - shell: |
            #!/bin/bash
            #
            # This script determines overall result of jenkins job
            #
            exit `cat ${TREE_NAME}/build.result`

            echo "Old build number"
            echo $PREV_BUILD_NUMBER

            BUILD_DIR=${TREE_NAME}/_install_/${GIT_DESCRIBE}/${arch}-${defconfig}
            BUILD_META=${BUILD_DIR}/build.meta

            grep build_result: ${BUILD_META} |grep -cq PASS
            RC=$?

            exit $RC
    publishers:
        - groovy-postbuild:
            script: |
                def build_number = manager.build.getEnvironment(manager.listener)['BUILD_NUMBER']
                def tree_name = manager.build.getEnvironment(manager.listener)['TREE_NAME']
                def branch = manager.build.getEnvironment(manager.listener)["BRANCH"]
                def description = manager.build.getEnvironment(manager.listener)['GIT_DESCRIBE']
                def arch = manager.build.getEnvironment(manager.listener)['ARCH_LIST']
                def publish = manager.build.getEnvironment(manager.listener)['PUBLISH']
                def resultsUrl="https://kernelci.org/build/${tree_name}/kernel/${description}/"

                def jobDescription = " ARCH: ${arch}"
                // FIXME: resultsURL is only valid when PUBLISH = "true"
                jobDescription = jobDescription + ",&nbsp;<a href='${resultsUrl}'>Results db</a>"

                manager.build.setDisplayName("#" + build_number + "-" + tree_name + '/' + branch + "-" + description)
                manager.build.setDescription(jobDescription)

                def cause = manager.build.getAction(hudson.model.CauseAction.class).getCauses()
                def upstreamBuild = cause[0].upstreamBuild
                def upstreamProject = cause[0].upstreamProject
                def jobName = upstreamProject
                def jobConfiguration = upstreamProject

                // Multi-configuration project
                if (upstreamProject.contains("/")) {
                  jobName = upstreamProject.split("/")[0]
                  jobConfiguration = upstreamProject.split("/")[1]
                }

                def jobs = hudson.model.Hudson.instance.getItem(jobName).getAllJobs()

                for (job in jobs) {
                  if(job.name == jobConfiguration) {
                    job.getLastBuild().setDisplayName("#" + build_number + "-" + tree_name + '/' + branch + "-" + description)
                    job.getLastBuild().setDescription(jobDescription)
                  }
                }
        - trigger-parameterized-builds:
            - project: milo-kernel-build-complete
              property-file: ${TREE_NAME}/env.properties
              condition: ALWAYS
              predefined-parameters: |
                  PUBLISH=${PUBLISH}
                  TREE_NAME=${TREE_NAME}
                  ARCH_LIST=${ARCH_LIST}
                  GIT_DESCRIBE=${GIT_DESCRIBE}