| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | /* | 
					
						
							|  |  |  |  * This pipeline is the "template" for the Asterisk Unit Tests multi-branch | 
					
						
							|  |  |  |  * parent job.  Jenkins will automatically scan the branches in the "asterisk" | 
					
						
							|  |  |  |  * or "Security-asterisk" projects in Gerrit and automatically create a branch- | 
					
						
							|  |  |  |  * specific job for each branch it finds this file in. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file starts as a declarative pipeline because with a declarative | 
					
						
							|  |  |  |  * pipeline, you can define the trigger in the pipeline file.  This keeps | 
					
						
							|  |  |  |  * everything in one place.  We transition to scripted pipeline later on because | 
					
						
							|  |  |  |  * we need to dynamically determine which docker image we're going to use and | 
					
						
							|  |  |  |  * you can't do that in a delcarative pipeline. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-11-19 10:59:07 -07:00
										 |  |  | def timeoutTime = 30 | 
					
						
							|  |  |  | def timeoutUnits = 'MINUTES' | 
					
						
							|  |  |  | if (env.TIMEOUT_UNITTESTS) { | 
					
						
							|  |  |  | 	def _timeout = env.TIMEOUT_UNITTESTS.split() | 
					
						
							|  |  |  | 	timeoutTime = _timeout[0].toInteger() | 
					
						
							|  |  |  | 	timeoutUnits = _timeout[1] | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | pipeline { | 
					
						
							| 
									
										
										
										
											2018-10-04 09:13:22 -06:00
										 |  |  | 	options { | 
					
						
							| 
									
										
										
										
											2019-08-08 06:12:18 -06:00
										 |  |  | 		ansiColor('gnome-terminal') | 
					
						
							|  |  |  | 		throttle(['asterisk-check']) | 
					
						
							| 
									
										
										
										
											2018-10-04 09:13:22 -06:00
										 |  |  | 		timestamps() | 
					
						
							| 
									
										
										
										
											2018-11-19 10:59:07 -07:00
										 |  |  | 		timeout(time: timeoutTime, unit: timeoutUnits) | 
					
						
							| 
									
										
										
										
											2018-10-04 09:13:22 -06:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 	triggers { | 
					
						
							|  |  |  | 		/* | 
					
						
							|  |  |  | 		 * This trigger will match either the "asterisk" or "Security-asterisk" | 
					
						
							|  |  |  | 		 * projects.  The branch is taken from the branch this job was created | 
					
						
							|  |  |  | 		 * for. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		gerrit customUrl: '', | 
					
						
							|  |  |  | 			commentTextParameterMode: 'PLAIN', | 
					
						
							|  |  |  | 			commitMessageParameterMode: 'PLAIN', | 
					
						
							|  |  |  | 			gerritBuildSuccessfulVerifiedValue: 1, | 
					
						
							|  |  |  | 			gerritBuildFailedVerifiedValue: -1, | 
					
						
							|  |  |  | 			gerritBuildUnstableVerifiedValue: -1, | 
					
						
							|  |  |  | 			gerritProjects: [ | 
					
						
							|  |  |  | 				[branches: [[compareType: 'PLAIN', pattern: "${BRANCH_NAME}"]], | 
					
						
							|  |  |  | 					compareType: 'REG_EXP', | 
					
						
							|  |  |  | 					disableStrictForbiddenFileVerification: false, | 
					
						
							|  |  |  | 					pattern: '^(Security-)?asterisk.*' | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			], | 
					
						
							|  |  |  | 			silentMode: false, | 
					
						
							|  |  |  | 			triggerOnEvents: [ | 
					
						
							|  |  |  | 				commentAddedContains('^recheck$'), | 
					
						
							|  |  |  | 				patchsetCreated(excludeDrafts: false, | 
					
						
							| 
									
										
										
										
											2019-02-07 15:52:56 +00:00
										 |  |  | 								excludeNoCodeChange: false, | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 								excludeTrivialRebase: false), | 
					
						
							|  |  |  | 				draftPublished() | 
					
						
							|  |  |  | 			], | 
					
						
							|  |  |  | 			skipVote: [ | 
					
						
							|  |  |  | 				onFailed: false, | 
					
						
							|  |  |  | 				onNotBuilt: true, | 
					
						
							|  |  |  | 				onSuccessful: false, | 
					
						
							|  |  |  | 				onUnstable: false | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	agent { | 
					
						
							|  |  |  | 		/* All of the stages need to be performed on a docker host */ | 
					
						
							| 
									
										
										
										
											2019-08-06 09:40:54 -06:00
										 |  |  | 		label "asterisk-check" | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	stages { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 		stage ("->") { | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 			/* | 
					
						
							|  |  |  | 			 * Jenkins will try to automatically rebuild this job when | 
					
						
							|  |  |  | 			 * the jenkinsfile changes but since this job is dependent on | 
					
						
							|  |  |  | 			 * Gerrit, we really don't want to do anything in that case. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			when { | 
					
						
							|  |  |  | 				not { environment name: 'GERRIT_CHANGE_NUMBER', value: '' } | 
					
						
							| 
									
										
										
										
											2018-07-16 12:30:26 -06:00
										 |  |  | 				not { environment name: 'GERRIT_EVENT_ACCOUNT_NAME', value: 'Jenkins2' } | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			steps { | 
					
						
							|  |  |  | 				script { | 
					
						
							| 
									
										
										
										
											2018-07-26 10:34:20 -06:00
										 |  |  | 					manager.build.displayName = "${env.GERRIT_CHANGE_NUMBER}" | 
					
						
							|  |  |  | 					manager.createSummary("/plugin/workflow-job/images/48x48/pipelinejob.png").appendText("Docker Host: ${NODE_NAME}", false) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 					stage ("Checkout") { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 						sh "sudo chown -R jenkins:users ." | 
					
						
							| 
									
										
										
										
											2019-02-27 09:37:14 -07:00
										 |  |  | 						env.GERRIT_PROJECT_URL = env.GIT_URL.replaceAll(/[^\/]+$/, env.GERRIT_PROJECT) | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 						/* | 
					
						
							|  |  |  | 						 * Jenkins has already automatically checked out the base branch | 
					
						
							|  |  |  | 						 * for this change but we now need to check out the change itself | 
					
						
							|  |  |  | 						 * and rebase it on the current base branch.  If the rebase fails, | 
					
						
							|  |  |  | 						 * that's an indication to the user that they'll need to sort their | 
					
						
							|  |  |  | 						 * change out. | 
					
						
							|  |  |  | 						 * | 
					
						
							|  |  |  | 						 * The Gerrit Trigger provides all the URLs and refspecs to | 
					
						
							|  |  |  | 						 * check out the change. | 
					
						
							| 
									
										
										
										
											2018-08-16 11:08:21 -06:00
										 |  |  | 						 * | 
					
						
							|  |  |  | 						 * We need to retrieve the jenkins2 gerrit https credentials | 
					
						
							|  |  |  | 						 * in case this review is in a restricted project. | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 						 */ | 
					
						
							| 
									
										
										
										
											2018-08-16 12:51:51 -06:00
										 |  |  | 						withCredentials([usernamePassword(credentialsId: "${JENKINS_GERRIT_CREDS}", | 
					
						
							|  |  |  | 							passwordVariable: 'GERRIT_USER_PW', usernameVariable: 'GERRIT_USER_NAME')]) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-08 11:10:11 -06:00
										 |  |  | 							sh "printenv -0 | sort -z | tr '\\0' '\\n'" | 
					
						
							| 
									
										
										
										
											2018-08-16 11:08:21 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							checkout scm: [$class: 'GitSCM', | 
					
						
							|  |  |  | 								branches: [[name: env.GERRIT_BRANCH ]], | 
					
						
							|  |  |  | 								extensions: [ | 
					
						
							| 
									
										
										
										
											2019-02-27 09:37:14 -07:00
										 |  |  | 									[$class: 'ScmName', name: env.GERRIT_NAME], | 
					
						
							| 
									
										
										
										
											2018-08-16 11:08:21 -06:00
										 |  |  | 									[$class: 'CleanBeforeCheckout'], | 
					
						
							|  |  |  | 									[$class: 'PreBuildMerge', options: [ | 
					
						
							| 
									
										
										
										
											2019-02-27 09:37:14 -07:00
										 |  |  | 										mergeRemote: env.GERRIT_NAME, | 
					
						
							| 
									
										
										
										
											2018-08-16 11:08:21 -06:00
										 |  |  | 										fastForwardMode: 'NO_FF', | 
					
						
							|  |  |  | 										mergeStrategy: 'RECURSIVE', | 
					
						
							|  |  |  | 										mergeTarget: env.GERRIT_BRANCH]], | 
					
						
							|  |  |  | 									[$class: 'CloneOption', | 
					
						
							|  |  |  | 										honorRefspec: true, | 
					
						
							|  |  |  | 										noTags: true, | 
					
						
							| 
									
										
										
										
											2019-12-02 05:48:01 -07:00
										 |  |  | 										shallow: false | 
					
						
							| 
									
										
										
										
											2018-08-16 11:08:21 -06:00
										 |  |  | 									], | 
					
						
							|  |  |  | 									[$class: 'PruneStaleBranch'], | 
					
						
							|  |  |  | 									[$class: 'BuildChooserSetting', | 
					
						
							|  |  |  | 										buildChooser: [$class: 'GerritTriggerBuildChooser'] | 
					
						
							|  |  |  | 									] | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 								], | 
					
						
							| 
									
										
										
										
											2018-08-16 11:08:21 -06:00
										 |  |  | 								userRemoteConfigs: [ | 
					
						
							|  |  |  | 									[ | 
					
						
							|  |  |  | 									credentialsId: env.JENKINS_GERRIT_CREDS, | 
					
						
							|  |  |  | 									name: env.GERRIT_NAME, | 
					
						
							|  |  |  | 									refspec: env.GERRIT_REFSPEC, | 
					
						
							| 
									
										
										
										
											2018-08-16 12:51:51 -06:00
										 |  |  | 									url: env.GERRIT_PROJECT_URL.replaceAll("http(s)?://", "http\$1://${GERRIT_USER_NAME}@") | 
					
						
							| 
									
										
										
										
											2018-08-16 11:08:21 -06:00
										 |  |  | 									] | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 								] | 
					
						
							|  |  |  | 							] | 
					
						
							| 
									
										
										
										
											2018-08-16 11:08:21 -06:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						sh "sudo tests/CI/setupJenkinsEnvironment.sh" | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					def images = env.DOCKER_IMAGES.split(' ') | 
					
						
							|  |  |  | 					def r = currentBuild.startTimeInMillis % images.length | 
					
						
							|  |  |  | 					def ri = images[(int)r] | 
					
						
							|  |  |  | 					def randomImage = env.DOCKER_REGISTRY + "/" + ri; | 
					
						
							| 
									
										
										
										
											2018-07-16 06:16:51 -06:00
										 |  |  | 					def bt = env.BUILD_TAG.replaceAll(/[^a-zA-Z0-9_.-]/, '-') | 
					
						
							| 
									
										
										
										
											2018-07-24 04:39:30 -06:00
										 |  |  | 					def dockerOptions = "--privileged --ulimit core=0 --ulimit nofile=10240 " + | 
					
						
							| 
									
										
										
										
											2019-02-19 16:06:32 +00:00
										 |  |  | 						" --tmpfs /tmp:exec,size=1G -v /srv/jenkins:/srv/jenkins:rw -v /srv/cache:/srv/cache:rw " + | 
					
						
							| 
									
										
										
										
											2018-07-16 06:16:51 -06:00
										 |  |  | 						" --entrypoint='' --name ${bt}-build" | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 					def outputdir = "tests/CI/output/UnitTests" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-26 10:34:20 -06:00
										 |  |  | 					manager.createSummary("/plugin/workflow-job/images/48x48/pipelinejob.png").appendText("Docker Image: ${randomImage}", false) | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 					def img = docker.image(randomImage) | 
					
						
							|  |  |  | 					img.pull() | 
					
						
							|  |  |  | 					img.inside(dockerOptions) { | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						stage ('Build') { | 
					
						
							|  |  |  | 							echo 'Building..' | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 09:20:20 -06:00
										 |  |  | 							sh "./tests/CI/buildAsterisk.sh --branch-name=${BRANCH_NAME} --output-dir=${outputdir} --cache-dir=/srv/cache" | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: false, | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 								artifacts: "${outputdir}/*" | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						stage ('Test') { | 
					
						
							|  |  |  | 							def outputfile = "${outputdir}/unittests-results.xml" | 
					
						
							|  |  |  | 							def testcmd = "test execute all" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-27 12:23:02 -06:00
										 |  |  | 							sh "sudo ./tests/CI/installAsterisk.sh --uninstall-all --branch-name=${BRANCH_NAME} --user-group=jenkins:users" | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-23 11:23:22 -04:00
										 |  |  | 							sh "tests/CI/runUnittests.sh --user-group=jenkins:users --output-dir='${outputdir}' --output-xml='${outputfile}' --unittest-command='${testcmd}'" | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: true, | 
					
						
							|  |  |  | 								artifacts: "${outputdir}/**" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							junit testResults: outputfile, | 
					
						
							|  |  |  | 								healthScaleFactor: 1.0, | 
					
						
							|  |  |  | 								keepLongStdio: true | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	post { | 
					
						
							| 
									
										
										
										
											2018-07-16 07:44:25 -06:00
										 |  |  | 		cleanup { | 
					
						
							| 
									
										
										
										
											2019-11-19 10:40:09 -07:00
										 |  |  | 			script { | 
					
						
							|  |  |  | 				if (env.CLEANUP_WS_UNITTESTS.toBoolean()) { | 
					
						
							|  |  |  | 					cleanWs deleteDirs: true, notFailBuild: false | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-11-19 07:51:56 -07:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-07-11 14:09:19 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		/* | 
					
						
							|  |  |  | 		 * The Gerrit Trigger will automatically post the "Verified" results back | 
					
						
							|  |  |  | 		 * to Gerrit but the verification publisher publishes extra stuff in the | 
					
						
							|  |  |  | 		 * "Code Review" section of the review. | 
					
						
							| 
									
										
										
										
											2018-07-16 07:44:25 -06:00
										 |  |  | 		 */ | 
					
						
							|  |  |  | 		always { | 
					
						
							|  |  |  | 			script { | 
					
						
							|  |  |  | 				def cat | 
					
						
							|  |  |  | 				def comment | 
					
						
							|  |  |  | 				def rvalue | 
					
						
							|  |  |  | 				switch (currentBuild.currentResult) { | 
					
						
							|  |  |  | 					case ~/^SUCCESS$/: | 
					
						
							|  |  |  | 						cat = "Passed" | 
					
						
							|  |  |  | 						comment = "" | 
					
						
							|  |  |  | 						rvalue = 1 | 
					
						
							|  |  |  | 						break | 
					
						
							|  |  |  | 					case ~/^FAILURE$/: | 
					
						
							|  |  |  | 						cat = "Failed" | 
					
						
							|  |  |  | 						comment = "Fatal Error" | 
					
						
							|  |  |  | 						rvalue = -1 | 
					
						
							|  |  |  | 						break | 
					
						
							|  |  |  | 					case ~/^UNSTABLE$/: | 
					
						
							|  |  |  | 						cat = "Failed" | 
					
						
							|  |  |  | 						comment = "Tests Failed" | 
					
						
							|  |  |  | 						rvalue = -1 | 
					
						
							|  |  |  | 						break | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				gerritverificationpublisher verifyStatusValue: rvalue, | 
					
						
							|  |  |  | 					verifyStatusCategory: cat, verifyStatusURL: '', | 
					
						
							|  |  |  | 					verifyStatusComment: comment, verifyStatusName: '', | 
					
						
							|  |  |  | 					verifyStatusReporter: 'Jenkins2', verifyStatusRerun: 'regate' | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 		success { | 
					
						
							| 
									
										
										
										
											2018-07-16 07:44:25 -06:00
										 |  |  | 			echo "Reporting ${currentBuild.currentResult} Passed" | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		failure { | 
					
						
							| 
									
										
										
										
											2018-07-16 07:44:25 -06:00
										 |  |  | 			echo "Reporting ${currentBuild.currentResult}: Failed: Fatal Error" | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		unstable { | 
					
						
							| 
									
										
										
										
											2018-07-16 07:44:25 -06:00
										 |  |  | 			echo "Reporting ${currentBuild.currentResult}: Failed: Tests Failed" | 
					
						
							| 
									
										
										
										
											2018-07-11 05:14:49 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |