Skip to content

Commit 998bc9b

Browse files
thst-nordiccarlescufi
authored andcommitted
[nrf noup] ci: use Standard Library in Jenkinsfile
Managing Docker version, Agent Labels, Github Status, manifest updates, downstream jobs from CI_LIB. Signed-off-by: Thomas Stilwell <[email protected]>
1 parent 09b7220 commit 998bc9b

File tree

1 file changed

+95
-27
lines changed

1 file changed

+95
-27
lines changed

Jenkinsfile

Lines changed: 95 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,78 @@
1-
def IMAGE_TAG = "ncs-toolchain:1.07"
2-
def REPO_CI_TOOLS = "https://github.com/zephyrproject-rtos/ci-tools.git"
1+
2+
@Library("CI_LIB") _
3+
4+
def AGENT_LABELS = lib_Main.getAgentLabels(JOB_NAME)
5+
def IMAGE_TAG = lib_Main.getDockerImage(JOB_NAME)
6+
def TIMEOUT = lib_Main.getTimeout(JOB_NAME)
7+
def INPUT_STATE = lib_Main.getInputState(JOB_NAME)
8+
def CI_STATE = new HashMap()
39

410
pipeline {
11+
12+
parameters {
13+
booleanParam(name: 'RUN_DOWNSTREAM', description: 'if false skip downstream jobs', defaultValue: true)
14+
booleanParam(name: 'RUN_TESTS', description: 'if false skip testing', defaultValue: true)
15+
booleanParam(name: 'RUN_BUILD', description: 'if false skip building', defaultValue: true)
16+
string(name: 'jsonstr_CI_STATE', description: 'Default State if no upstream job', defaultValue: INPUT_STATE)
17+
}
18+
519
agent {
620
docker {
7-
image "$IMAGE_TAG"
8-
label "docker && build-node && ncs"
21+
image IMAGE_TAG
22+
label AGENT_LABELS
23+
args '-e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/workdir/.local/bin'
924
}
1025
}
1126
options {
1227
// Checkout the repository to this folder instead of root
1328
checkoutToSubdirectory('mcuboot')
29+
timeout(time: TIMEOUT.time, unit: TIMEOUT.unit)
1430
}
1531

1632
environment {
1733
// This token is used to by check_compliance to comment on PRs and use checks
1834
GH_TOKEN = credentials('nordicbuilder-compliance-token')
1935
GH_USERNAME = "NordicBuilder"
20-
COMPLIANCE_SCRIPT_PATH = "../ci-tools/scripts/check_compliance.py"
2136
COMPLIANCE_ARGS = "-r NordicPlayground/fw-nrfconnect-mcuboot"
22-
COMPLIANCE_REPORT_ARGS = "-p $CHANGE_ID -S $GIT_COMMIT -g"
2337
}
2438

2539
stages {
26-
stage('Checkout repositories') {
27-
steps {
28-
dir("ci-tools") {
29-
git branch: "master", url: "$REPO_CI_TOOLS"
30-
}
31-
}
40+
stage('Load') { steps { script { CI_STATE = lib_Stage.load('MCUBOOT') }}}
41+
stage('Checkout') {
42+
steps { script {
43+
lib_Main.cloneCItools(JOB_NAME)
44+
CI_STATE.MCUBOOT.REPORT_SHA = lib_Main.checkoutRepo(CI_STATE.MCUBOOT.GIT_URL, "mcuboot", CI_STATE.MCUBOOT, false)
45+
lib_West.AddManifestUpdate("MCUBOOT", 'mcuboot', CI_STATE.MCUBOOT.GIT_URL, CI_STATE.MCUBOOT.GIT_REF, CI_STATE)
46+
}}
3247
}
33-
3448
stage('Run compliance check') {
49+
when { expression { CI_STATE.MCUBOOT.RUN_TESTS } }
3550
steps {
36-
dir('mcuboot') {
37-
script {
38-
// If we're a pull request, compare the target branch against the current HEAD (the PR)
39-
if (env.CHANGE_TARGET) {
40-
COMMIT_RANGE = "origin/${env.CHANGE_TARGET}..HEAD"
41-
COMPLIANCE_ARGS = "$COMPLIANCE_ARGS $COMPLIANCE_REPORT_ARGS"
51+
script {
52+
lib_Status.set("PENDING", 'MCUBOOT', CI_STATE);
53+
dir('mcuboot') {
54+
def BUILD_TYPE = lib_Main.getBuildType(CI_STATE.MCUBOOT)
55+
if (BUILD_TYPE == "PR") {
56+
COMMIT_RANGE = "$CI_STATE.MCUBOOT.MERGE_BASE..$CI_STATE.MCUBOOT.REPORT_SHA"
57+
COMPLIANCE_ARGS = "$COMPLIANCE_ARGS -p $CHANGE_ID -S $CI_STATE.MCUBOOT.REPORT_SHA -g"
58+
println "Building a PR [$CHANGE_ID]: $COMMIT_RANGE"
59+
}
60+
else if (BUILD_TYPE == "TAG") {
61+
COMMIT_RANGE = "tags/${env.BRANCH_NAME}..tags/${env.BRANCH_NAME}"
62+
println "Building a Tag: " + COMMIT_RANGE
4263
}
4364
// If not a PR, it's a non-PR-branch or master build. Compare against the origin.
44-
else {
65+
else if (BUILD_TYPE == "BRANCH") {
4566
COMMIT_RANGE = "origin/${env.BRANCH_NAME}..HEAD"
67+
println "Building a Branch: " + COMMIT_RANGE
4668
}
69+
else {
70+
assert condition : "Build fails because it is not a PR/Tag/Branch"
71+
}
72+
4773
// Run the compliance check
4874
try {
49-
sh "$COMPLIANCE_SCRIPT_PATH $COMPLIANCE_ARGS --commits $COMMIT_RANGE"
75+
sh "../ci-tools/scripts/check_compliance.py $COMPLIANCE_ARGS --commits $COMMIT_RANGE"
5076
}
5177
finally {
5278
junit 'compliance.xml'
@@ -56,27 +82,69 @@ pipeline {
5682
}
5783
}
5884
}
85+
stage('Build samples') {
86+
when { expression { CI_STATE.MCUBOOT.RUN_BUILD } }
87+
steps {
88+
echo "No Samples to build yet."
89+
}
90+
}
91+
stage('Trigger testing build') {
92+
when { expression { CI_STATE.MCUBOOT.RUN_DOWNSTREAM } }
93+
steps {
94+
script {
95+
CI_STATE.MCUBOOT.WAITING = true
96+
def DOWNSTREAM_JOBS = lib_Main.getDownStreamJobs(JOB_NAME)
97+
def jobs = [:]
98+
DOWNSTREAM_JOBS.each {
99+
jobs["${it}"] = {
100+
build job: "${it}", propagate: true, wait: true, parameters: [
101+
string(name: 'jsonstr_CI_STATE', value: lib_Util.HashMap2Str(CI_STATE))]
102+
}
103+
}
104+
parallel jobs
105+
}
106+
}
107+
}
108+
59109
}
60110

61111
post {
112+
// This is the order that the methods are run. {always->success/abort/failure/unstable->cleanup}
62113
always {
63-
// Clean up the working space at the end (including tracked files)
64-
cleanWs()
114+
echo "always"
115+
}
116+
success {
117+
echo "success"
118+
script { lib_Status.set("SUCCESS", 'MCUBOOT', CI_STATE) }
119+
}
120+
aborted {
121+
echo "aborted"
122+
script { lib_Status.set("ABORTED", 'MCUBOOT', CI_STATE) }
123+
}
124+
unstable {
125+
echo "unstable"
65126
}
66127
failure {
128+
echo "failure"
129+
script { lib_Status.set("FAILURE", 'MCUBOOT', CI_STATE) }
67130
script{
68131
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME.startsWith("PR"))
69132
{
70-
emailext(to: 'anpu',
71-
body: "${currentBuild.currentResult}\nJob ${env.JOB_NAME}\t\t build ${env.BUILD_NUMBER}\r\nLink: ${env.BUILD_URL}",
72-
subject: "[Jenkins][Build ${currentBuild.currentResult}: ${env.JOB_NAME}]",
73-
mimeType: 'text/html',)
133+
// emailext(to: 'anpu',
134+
// body: "${currentBuild.currentResult}\nJob ${env.JOB_NAME}\t\t build ${env.BUILD_NUMBER}\r\nLink: ${env.BUILD_URL}",
135+
// subject: "[Jenkins][Build ${currentBuild.currentResult}: ${env.JOB_NAME}]",
136+
// mimeType: 'text/html',)
74137
}
75138
else
76139
{
77140
echo "Branch ${env.BRANCH_NAME} is not master nor PR. Sending failure email skipped."
78141
}
79142
}
80143
}
144+
cleanup {
145+
echo "cleanup"
146+
// Clean up the working space at the end (including tracked files)
147+
cleanWs()
148+
}
81149
}
82150
}

0 commit comments

Comments
 (0)