forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
181 lines (164 loc) · 6.81 KB
/
Jenkinsfile
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
// Due to JENKINS-42369 we put these defines outside the pipeline
def IMAGE_TAG = "ncs-toolchain:1.07"
def REPO_CI_TOOLS = "https://github.com/zephyrproject-rtos/ci-tools.git"
// Function to get the current repo URL, to be propagated to the downstream job
def getRepoURL() {
dir('nrf') {
sh "git config --get remote.origin.url > .git/remote-url"
return readFile(".git/remote-url").trim()
}
}
def check_and_store_sample(path, new_name) {
script {
if (fileExists(file_path)) {
sh "cp ${path} artifacts/${new_name}"
}
else {
echo "Build for ${new_name} failed"
currentBuild.result = 'FAILURE'
}
}
}
pipeline {
agent {
docker {
image "$IMAGE_TAG"
label "docker && ncs"
args '-e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/workdir/.local/bin'
}
}
options {
// Checkout the repository to this folder instead of root
checkoutToSubdirectory('nrf')
}
environment {
// ENVs for check-compliance
GH_TOKEN = credentials('nordicbuilder-compliance-token') // This token is used to by check_compliance to comment on PRs and use checks
GH_USERNAME = "NordicBuilder"
COMPLIANCE_ARGS = "-r NordicPlayground/fw-nrfconnect-nrf"
COMPLIANCE_REPORT_ARGS = "-p $CHANGE_ID -S $GIT_COMMIT -g"
// Build all custom samples that match the ci_build tag
SANITYCHECK_OPTIONS = "--board-root $WORKSPACE/nrf/boards --testcase-root $WORKSPACE/nrf/samples --testcase-root $WORKSPACE/nrf/applications --build-only --disable-unrecognized-section-test -t ci_build --inline-logs"
ARCH = "-a arm"
LC_ALL = "C.UTF-8"
// ENVs for building (triggered by sanitycheck)
ZEPHYR_TOOLCHAIN_VARIANT = 'gnuarmemb'
GNUARMEMB_TOOLCHAIN_PATH = '/workdir/gcc-arm-none-eabi-7-2018-q2-update'
// Projects to trigger after this one is built
DOWNSTREAM_PROJECTS = credentials('fw-nrfconnect-nrf-jobs')
}
stages {
stage('Checkout repositories') {
steps {
// Fetch the tools used to checking compliance
dir("ci-tools") {
git branch: "master", url: "$REPO_CI_TOOLS"
}
// Install and initialize west
sh "pip3 install --user west==0.5.1"
sh "west init -l nrf/"
// Checkout
sh "west update"
}
}
stage('Testing') {
parallel {
stage('Build samples') {
steps {
// Create a folder to store artifacts in
sh 'mkdir artifacts'
// Build all the samples
dir('zephyr') {
sh "source zephyr-env.sh && ./scripts/sanitycheck $SANITYCHECK_OPTIONS"
}
script {
/* Rename the nrf52 desktop samples */
desktop_platforms = ['nrf52840_pca20041', 'nrf52840_pca10056', 'nrf52840_pca10059']
for(int i=0; i<desktop_platforms.size(); i++) {
file_path = "zephyr/sanity-out/${desktop_platforms[i]}/nrf_desktop/test/zephyr/zephyr.hex"
check_and_store_sample("$file_path", "nrf_desktop_${desktop_platforms[i]}.hex")
file_path = "zephyr/sanity-out/${desktop_platforms[i]}/nrf_desktop/test_zrelease/zephyr/zephyr.hex"
check_and_store_sample("$file_path", "nrf_desktop_${desktop_platforms[i]}_ZRelease.hex")
}
/* Rename the nrf9160 samples */
samples = ['secure_boot']
for(int i=0; i<samples.size(); i++)
{
file_path = "zephyr/sanity-out/nrf9160_pca10090/nrf9160/${samples[i]}/test_build/zephyr/zephyr.hex"
check_and_store_sample("$file_path", "${samples[i]}_nrf9160_pca10090.hex")
}
ns_samples = ['lte_ble_gateway', 'at_client']
for(int i=0; i<ns_samples.size(); i++)
{
file_path = "zephyr/sanity-out/nrf9160_pca10090ns/nrf9160/${ns_samples[i]}/test_build/zephyr/zephyr.hex"
check_and_store_sample("$file_path", "${ns_samples[i]}_nrf9160_pca10090ns.hex")
}
ns_apps = ['asset_tracker']
for(int i=0; i<ns_apps.size(); i++)
{
file_path = "zephyr/sanity-out/nrf9160_pca10090ns/${ns_apps[i]}/test_build/zephyr/zephyr.hex"
check_and_store_sample("$file_path", "${ns_apps[i]}_nrf9160_pca10090ns.hex")
}
}
archiveArtifacts allowEmptyArchive: true, artifacts: 'artifacts/*.hex'
}
}
stage('Run compliance check') {
steps {
// Define a Groovy script block, which allows things like try/catch and if/else. If not, the junit command will not be run if check-compliance fails
dir('nrf') {
script {
// If we're a pull request, compare the target branch against the current HEAD (the PR), and also report issues to the PR
if (env.CHANGE_TARGET) {
COMMIT_RANGE = "origin/${env.CHANGE_TARGET}..HEAD"
COMPLIANCE_ARGS = "$COMPLIANCE_ARGS $COMPLIANCE_REPORT_ARGS"
}
// If not a PR, it's a non-PR-branch or master build. Compare against the origin.
else {
COMMIT_RANGE = "origin/${env.BRANCH_NAME}..HEAD"
}
// Run the compliance check
try {
sh "(source ../zephyr/zephyr-env.sh && ../ci-tools/scripts/check_compliance.py $COMPLIANCE_ARGS --commits $COMMIT_RANGE)"
}
finally {
junit 'compliance.xml'
archiveArtifacts artifacts: 'compliance.xml'
}
}
}
}
}
}
}
stage('Trigger testing build') {
steps {
script {
if (env.CHANGE_TITLE) {
PR_NAME = "${env.CHANGE_TITLE}"
}
else {
PR_NAME = "$BRANCH_NAME"
}
def projs = [:]
env.DOWNSTREAM_PROJECTS.split(',').each {
projs["${it}"] = {
build job: "${it}", propagate: true, wait: false, parameters: [string(name: 'branchname', value: "$BRANCH_NAME"),
string(name: 'API_URL', value: "${getRepoURL()}"),
string(name: 'API_COMMIT', value: "$GIT_COMMIT"),
string(name: 'API_PR_NAME', value: "$PR_NAME"),
string(name: 'API_RUN_NUMBER', value: "$BUILD_NUMBER")]
}
}
parallel projs
}
}
}
}
post {
always {
// Clean up the working space at the end (including tracked files)
cleanWs()
}
}
}