1- def IMAGE_TAG = " ncs-toolchain:1.08"
2- def REPO_CI_TOOLS = " https://github.com/zephyrproject-rtos/ci-tools.git"
3- def REPO_CI_TOOLS_SHA = " bfe635f102271a4ad71c1a14824f9d5e64734e57"
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 ()
49
510pipeline {
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' ,
17+ defaultValue : INPUT_STATE )
18+ }
19+
620 agent {
721 docker {
8- image " $ IMAGE_TAG "
9- label " docker && build-node && ncs && linux "
22+ image IMAGE_TAG
23+ label AGENT_LABELS
1024 args ' -e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/workdir/.local/bin'
1125 }
1226 }
1327 options {
1428 // Checkout the repository to this folder instead of root
1529 checkoutToSubdirectory(' zephyr' )
30+ timeout(time : TIMEOUT . time, unit : TIMEOUT . unit)
1631 }
1732
1833 environment {
1934 // ENVs for check-compliance
2035 GH_TOKEN = credentials(' nordicbuilder-compliance-token' ) // This token is used to by check_compliance to comment on PRs and use checks
2136 GH_USERNAME = " NordicBuilder"
2237 COMPLIANCE_ARGS = " -r NordicPlayground/fw-nrfconnect-zephyr --exclude-module Kconfig"
23- COMPLIANCE_REPORT_ARGS = " -p $CHANGE_ID -S $GIT_COMMIT -g"
2438
2539 LC_ALL = " C.UTF-8"
2640
@@ -37,91 +51,120 @@ pipeline {
3751 }
3852
3953 stages {
40- stage(' Checkout repositories' ) {
41- steps {
42- dir(" ci-tools" ) {
43- git branch : " master" , url : " $REPO_CI_TOOLS "
44- sh " git checkout ${ REPO_CI_TOOLS_SHA} "
45- }
54+ stage(' Load' ) { steps { script { CI_STATE = lib_Stage. load(' ZEPHYR' ) }}}
55+ stage(' Checkout' ) {
56+ steps { script {
57+ lib_Main. cloneCItools(JOB_NAME )
4658 dir(' zephyr' ) {
47- sh " git rev-parse HEAD"
59+ CI_STATE . ZEPHYR . REPORT_SHA = lib_Main. checkoutRepo(CI_STATE . ZEPHYR . GIT_URL , " ZEPHYR" , CI_STATE . ZEPHYR , false )
60+ lib_West.AddManifestUpdate (" ZEPHYR" , ' zephyr' , CI_STATE . ZEPHYR . GIT_URL , CI_STATE . ZEPHYR . GIT_REF , CI_STATE )
4861 }
49-
50- // Initialize west
51- sh " west init -l zephyr/"
52-
53- // Checkout
54- sh " west update"
55- }
62+ }}
5663 }
64+ stage(' Get nRF && Apply Parent Manifest Updates' ) {
65+ when { expression { CI_STATE . ZEPHYR . RUN_TESTS || CI_STATE . ZEPHYR . RUN_BUILD } }
66+ steps { script {
67+ lib_Status. set(" PENDING" , ' ZEPHYR' , CI_STATE );
68+ lib_West.InitUpdate (' zephyr' )
69+ lib_West.ApplyManifestUpdates (CI_STATE )
70+ }}
71+ }
72+ stage(' Run compliance check' ) {
73+ when { expression { CI_STATE . ZEPHYR . RUN_TESTS } }
74+ steps {
75+ dir(' zephyr' ) {
76+ script {
77+ def BUILD_TYPE = lib_Main. getBuildType(CI_STATE . ZEPHYR )
78+ if (BUILD_TYPE == " PR" ) {
79+ COMMIT_RANGE = " $CI_STATE . ZEPHYR . MERGE_BASE .. $CI_STATE . ZEPHYR . REPORT_SHA "
80+ COMPLIANCE_ARGS = " $COMPLIANCE_ARGS -p $CHANGE_ID -S $CI_STATE . ZEPHYR . REPORT_SHA -g"
81+ println " Building a PR [$CHANGE_ID ]: $COMMIT_RANGE "
82+ }
83+ else if (BUILD_TYPE == " TAG" ) {
84+ COMMIT_RANGE = " tags/${ env.BRANCH_NAME} ..tags/${ env.BRANCH_NAME} "
85+ println " Building a Tag: " + COMMIT_RANGE
86+ }
87+ // If not a PR, it's a non-PR-branch or master build. Compare against the origin.
88+ else if (BUILD_TYPE == " BRANCH" ) {
89+ COMMIT_RANGE = " origin/${ env.BRANCH_NAME} ..HEAD"
90+ println " Building a Branch: " + COMMIT_RANGE
91+ }
92+ else {
93+ assert condition : " Build fails because it is not a PR/Tag/Branch"
94+ }
5795
58- stage(' Testing' ) {
59- parallel {
60- stage(' Run compliance check' ) {
61- steps {
62- dir(' zephyr' ) {
63- script {
64- // If we're a pull request, compare the target branch against the current HEAD (the PR)
65- println " CHANGE_TARGET = ${ env.CHANGE_TARGET} "
66- println " BRANCH_NAME = ${ env.BRANCH_NAME} "
67- println " TAG_NAME = ${ env.TAG_NAME} "
68-
69- if (env. CHANGE_TARGET ) {
70- COMMIT_RANGE = " origin/${ env.CHANGE_TARGET} ..HEAD"
71- COMPLIANCE_ARGS = " $COMPLIANCE_ARGS $COMPLIANCE_REPORT_ARGS "
72- sh " echo change id: $CHANGE_ID "
73- sh " echo git commit: $GIT_COMMIT "
74- sh " echo commit range: $COMMIT_RANGE "
75- sh " git rev-parse origin/$CHANGE_TARGET "
76- sh " git rev-parse HEAD"
77- println " Building a PR: ${ COMMIT_RANGE} "
78- }
79- else if (env. TAG_NAME ) {
80- COMMIT_RANGE = " tags/${ env.BRANCH_NAME} ..tags/${ env.BRANCH_NAME} "
81- println " Building a Tag: ${ COMMIT_RANGE} "
82- }
83- // If not a PR, it's a non-PR-branch or master build. Compare against the origin.
84- else if (env. BRANCH_NAME ) {
85- COMMIT_RANGE = " origin/${ env.BRANCH_NAME} ..HEAD"
86- println " Building a Branch: ${ COMMIT_RANGE} "
87- }
88- else {
89- assert condition : " Build fails because it is not a PR/Tag/Branch"
90- }
91- // Run the compliance check
92- try {
93- sh " (source zephyr-env.sh && ../ci-tools/scripts/check_compliance.py $COMPLIANCE_ARGS --commits $COMMIT_RANGE )"
94- }
95- finally {
96- junit ' compliance.xml'
97- archiveArtifacts artifacts : ' compliance.xml'
98- }
99- }
96+ // Run the compliance check
97+ try {
98+ sh " (source ../zephyr/zephyr-env.sh && ../ci-tools/scripts/check_compliance.py $COMPLIANCE_ARGS --commits $COMMIT_RANGE )"
99+ }
100+ finally {
101+ junit ' compliance.xml'
102+ archiveArtifacts artifacts : ' compliance.xml'
100103 }
101104 }
102105 }
106+ }
107+ }
108+ stage(' Sanitycheck (all)' ) {
109+ when { expression { CI_STATE . ZEPHYR . RUN_BUILD } }
110+ steps {
111+ dir(' zephyr' ) {
112+ sh " ls -alh "
113+ sh " echo variant: $ZEPHYR_TOOLCHAIN_VARIANT "
114+ sh " echo SDK dir: $ZEPHYR_SDK_INSTALL_DIR "
115+ sh " cat /opt/zephyr-sdk/sdk_version"
116+ sh " source zephyr-env.sh && \
117+ (./scripts/sanitycheck $SANITYCHECK_OPTIONS $ARCH || \
118+ (sleep 10; ./scripts/sanitycheck $SANITYCHECK_OPTIONS $SANITYCHECK_RETRY ) || \
119+ (sleep 10; ./scripts/sanitycheck $SANITYCHECK_OPTIONS $SANITYCHECK_RETRY_2 ))"
120+ }
121+ }
122+ }
123+
124+ stage(' Trigger testing build' ) {
125+ when { expression { CI_STATE . ZEPHYR . RUN_DOWNSTREAM } }
126+ steps {
127+ script {
128+ CI_STATE . ZEPHYR . WAITING = true
129+ def DOWNSTREAM_JOBS = lib_Main. getDownStreamJobs(JOB_NAME )
130+ println " DOWNSTREAM_JOBS = " + DOWNSTREAM_JOBS
103131
104- stage(' Sanitycheck (all)' ) {
105- steps {
106- dir(' zephyr' ) {
107- sh " echo variant: $ZEPHYR_TOOLCHAIN_VARIANT "
108- sh " echo SDK dir: $ZEPHYR_SDK_INSTALL_DIR "
109- sh " cat /opt/zephyr-sdk/sdk_version"
110- sh " source zephyr-env.sh && \
111- (./scripts/sanitycheck $SANITYCHECK_OPTIONS $ARCH || \
112- (sleep 10; ./scripts/sanitycheck $SANITYCHECK_OPTIONS $SANITYCHECK_RETRY ) || \
113- (sleep 10; ./scripts/sanitycheck $SANITYCHECK_OPTIONS $SANITYCHECK_RETRY_2 ))"
132+ def jobs = [:]
133+ DOWNSTREAM_JOBS . each {
134+ jobs[" ${ it} " ] = {
135+ build job : " ${ it} " , propagate : true , wait : CI_STATE . ZEPHYR . WAITING , parameters : [
136+ string(name : ' jsonstr_CI_STATE' , value : lib_Util.HashMap2Str (CI_STATE ))]
114137 }
115138 }
139+ parallel jobs
116140 }
117141 }
118142 }
119143 }
120144
121145 post {
146+ // This is the order that the methods are run. {always->success/abort/failure/unstable->cleanup}
122147 always {
123- // Clean up the working space at the end (including tracked files)
124- cleanWs()
148+ echo " always"
149+ }
150+ success {
151+ echo " success"
152+ script { lib_Status. set(" SUCCESS" , ' ZEPHYR' , CI_STATE ) }
153+ }
154+ aborted {
155+ echo " aborted"
156+ script { lib_Status. set(" ABORTED" , ' ZEPHYR' , CI_STATE ) }
157+ }
158+ unstable {
159+ echo " unstable"
160+ }
161+ failure {
162+ echo " failure"
163+ script { lib_Status. set(" FAILURE" , ' ZEPHYR' , CI_STATE ) }
164+ }
165+ cleanup {
166+ echo " cleanup"
167+ cleanWs()
125168 }
126169 }
127170}
0 commit comments