forked from analogdevicesinc/precision-converters-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
154 lines (140 loc) · 5.58 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
@Library(['jenkins_shared_lib','pcts_jenkins_shared_lib']) _
groovyScriptsList = []
projectsNameList = []
buildStatus = "Success"
pipeline {
agent none
environment {
// Compiler type used is currently hard coded
TOOLCHAIN = "GCC_ARM"
// MBED_GCC_TOOLCHAIN_PATH is a global jenkins defined environment variable
TOOLCHAIN_PATH = "${MBED_GCC_TOOLCHAIN_PATH}"
}
options {
// This stops multiple copies of this job running, but not multiple parallel matrix builds
disableConcurrentBuilds()
// keeps some named stashes around so that pipeline stages can be restarted
preserveStashes(buildCount: 5)
// Set build log and artifact discarding policy
buildDiscarder(
logRotator(
// number of build logs to keep
numToKeepStr:'10',
// number of builds have their artifacts kept
artifactNumToKeepStr: '10'
)
)
}
stages {
stage("Load Build") { // Prepare/load build scripts
agent { label 'firmware_builder' }
steps {
script {
// Find the project changes
projectChanges = buildInfo.findProjectChanged()
// Get list of all the projects
def projectsList = []
def output = buildInfo.getProjectsList("${env.WORKSPACE}\\projects")
projectsList = output.tokenize('\n').collect() { it }
// Load project specific groovy scripts based on the project change
int cnt = 0
for (String projectName: projectsList) {
projectName = projectName.trim()
if (projectChanges.contains("$projectName") || projectChanges.contains("Jenkinsfile") || projectChanges.contains("libraries") || env.BRANCH_NAME=="main" || env.BRANCH_NAME=="develop") {
groovyScriptsList[cnt] = load "projects\\$projectName\\ci_build.groovy"
projectsNameList[cnt] = projectName
cnt++
}
}
}
}
post {
cleanup {
cleanWs()
}
}
}
stage("Build and Test") { // Run build and test scripts
agent { label 'firmware_builder' }
steps {
script {
// Checkout all submodules recursively
sh "git submodule update --init --recursive"
// Execute build and test job for each changed project
for (int cnt=0; cnt < groovyScriptsList.size(); cnt++) {
try {
// Get all build matrix combinations for current project
List buildMatrix = groovyScriptsList[cnt].getBuildMatrix("${projectsNameList[cnt]}");
// Build all matrix combinations for current project
echo "Number of build matrix combinations: ${buildMatrix.size()}"
for (int i = 0; i < buildMatrix.size(); i++) {
Map axis = buildMatrix[i]
groovyScriptsList[cnt].doBuild(axis, "${projectsNameList[cnt]}")
}
}
catch (Exception ex) {
echo "Failed in ${projectsNameList[cnt]}-Build"
echo "Caught:${ex}"
currentBuild.result = 'FAILURE'
buildStatus = 'Failure'
}
if (buildStatus != 'Failure') {
try {
// Get all test matrix combinations for current project
List testMatrix = groovyScriptsList[cnt].getTestMatrix("${projectsNameList[cnt]}");
// Test all matrix combinations for current project
echo "Number of test matrix combinations: ${testMatrix.size()}"
for (int i = 0; i < testMatrix.size(); i++) {
Map axis = testMatrix[i]
groovyScriptsList[cnt].doTest(axis, "${projectsNameList[cnt]}")
}
}
catch (Exception ex) {
echo "Failed in ${projectsNameList[cnt]}-Test"
echo "Caught:${ex}"
currentBuild.result = 'FAILURE'
}
}
}
}
}
post {
cleanup {
cleanWs()
}
}
}
stage('Check Licensing') { // Perform licensing scan
when {
expression { env.BRANCH_NAME == "main" || env.BRANCH_NAME == "develop" }
}
agent { label 'docker' }
steps {
script {
licensing.check()
}
}
}
}
post {
always {
// nothing to do
echo "always"
}
success {
// nothing to do
echo "success"
}
failure {
echo "failure"
}
unstable {
// nothing to do
echo "unstable"
}
changed {
// nothing to do
echo "changed"
}
}
}