-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
152 lines (138 loc) · 5.24 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
// Due to JENKINS-42369 we put these defines outside the pipeline
def IMAGE_TAG = "ncs-toolchain:1.06"
def REPO_ZEPHYR = "https://github.com/NordicPlayground/fw-nrfconnect-zephyr.git"
def REPO_NRFXLIB = "https://github.com/NordicPlayground/nrfxlib.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"
}
}
options {
// Checkout the repository to this folder instead of root
checkoutToSubdirectory('nrf')
}
environment {
// Build all custom samples that match the ci_build tag
SANITYCHECK_OPTIONS = "--board-root $WORKSPACE/nrf/boards --testcase-root $WORKSPACE/nrf/samples --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 {
dir("zephyr") {
git branch: "nrf91", url: "$REPO_ZEPHYR", credentialsId: 'github'
}
dir("nrfxlib") {
git branch: "master", url: "$REPO_NRFXLIB", credentialsId: 'github'
}
}
}
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', 'nrf52_pca63519']
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")
}
/* Rename the nrf9160 samples */
samples = ['secure_boot', 'asset_tracker', 'lte_ble_gateway', 'at_client']
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")
}
}
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
script {
// If we're a pull request, compare the target branch against the current HEAD (the PR)
if (env.CHANGE_TARGET) {
COMMIT_RANGE = "origin/${env.CHANGE_TARGET}..HEAD"
}
// 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 && cd nrf && ../zephyr/scripts/ci/check-compliance.py --commits $COMMIT_RANGE)"
}
finally {
junit 'nrf/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()
}
}
}