| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | /* | 
					
						
							|  |  |  |  * This pipeline is the "template" for the Asterisk Gate 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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | pipeline { | 
					
						
							|  |  |  | 	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: 2, | 
					
						
							|  |  |  | 			gerritBuildFailedVerifiedValue: -1, | 
					
						
							|  |  |  | 			gerritBuildUnstableVerifiedValue: -1, | 
					
						
							|  |  |  | 			gerritProjects: [ | 
					
						
							|  |  |  | 				[branches: [[compareType: 'PLAIN', pattern: "${BRANCH_NAME}"]], | 
					
						
							|  |  |  | 					compareType: 'REG_EXP', | 
					
						
							|  |  |  | 					disableStrictForbiddenFileVerification: false, | 
					
						
							|  |  |  | 					pattern: '^(Security-)?asterisk.*' | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			], | 
					
						
							|  |  |  | 			silentMode: false, | 
					
						
							|  |  |  | 			triggerOnEvents: [ | 
					
						
							|  |  |  | 				commentAddedContains('^regate$'), | 
					
						
							|  |  |  | 				commentAdded(commentAddedTriggerApprovalValue: '+2', verdictCategory: 'Code-Review'), | 
					
						
							|  |  |  | 			], | 
					
						
							|  |  |  | 			skipVote: [ | 
					
						
							|  |  |  | 				onFailed: false, | 
					
						
							|  |  |  | 				onNotBuilt: true, | 
					
						
							|  |  |  | 				onSuccessful: false, | 
					
						
							|  |  |  | 				onUnstable: false | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-11 14:55:55 -06:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 	agent { | 
					
						
							|  |  |  | 		/* All of the stages need to be performed on a docker host */ | 
					
						
							|  |  |  | 		label "swdev-docker" | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 	stages { | 
					
						
							|  |  |  | 		stage ("->") { | 
					
						
							|  |  |  | 			/* | 
					
						
							|  |  |  | 			 * 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 13:00:38 -06:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			steps { | 
					
						
							|  |  |  | 				/* Here's where we switch to scripted pipeline */ | 
					
						
							| 
									
										
										
										
											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 13:00:38 -06:00
										 |  |  | 				script { | 
					
						
							|  |  |  | 					stage ("Checkout") { | 
					
						
							| 
									
										
										
										
											2018-07-11 14:09:19 -06:00
										 |  |  | 						sh "sudo chown -R jenkins:users ."   | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 						env.GERRIT_PROJECT_URL = env.GERRIT_CHANGE_URL.replaceAll(/\/[0-9]+$/, "/${env.GERRIT_PROJECT}") | 
					
						
							|  |  |  | 						sh "printenv | sort" | 
					
						
							| 
									
										
										
										
											2018-07-11 14:09:19 -06:00
										 |  |  | 					 | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 						/* | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -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. | 
					
						
							|  |  |  | 						 * | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 						 * The Gerrit Trigger provides all the URLs and refspecs to | 
					
						
							|  |  |  | 						 * check out the change. | 
					
						
							|  |  |  | 						 */ | 
					
						
							|  |  |  | 						checkout scm: [$class: 'GitSCM', | 
					
						
							|  |  |  | 							branches: [[name: env.GERRIT_BRANCH ]], | 
					
						
							|  |  |  | 							extensions: [ | 
					
						
							| 
									
										
										
										
											2018-07-17 10:09:01 -06:00
										 |  |  | 								[$class: 'ScmName', name: 'gerrit-public'], | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 								[$class: 'CleanBeforeCheckout'], | 
					
						
							| 
									
										
										
										
											2018-07-17 09:15:58 -06:00
										 |  |  | 								[$class: 'PreBuildMerge', options: [ | 
					
						
							| 
									
										
										
										
											2018-07-17 10:09:01 -06:00
										 |  |  | 									mergeRemote: 'gerrit-public', | 
					
						
							|  |  |  | 									fastForwardMode: 'NO_FF', | 
					
						
							|  |  |  | 									mergeStrategy: 'RECURSIVE', | 
					
						
							|  |  |  | 									mergeTarget: env.GERRIT_BRANCH]], | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 								[$class: 'CloneOption', | 
					
						
							| 
									
										
										
										
											2018-07-17 08:01:46 -06:00
										 |  |  | 									honorRefspec: true, | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 									noTags: true, | 
					
						
							|  |  |  | 									depth: 10, | 
					
						
							|  |  |  | 									shallow: true | 
					
						
							|  |  |  | 								], | 
					
						
							| 
									
										
										
										
											2018-07-17 10:09:01 -06:00
										 |  |  | 								[$class: 'PruneStaleBranch'], | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 								[$class: 'BuildChooserSetting', | 
					
						
							|  |  |  | 									buildChooser: [$class: 'GerritTriggerBuildChooser'] | 
					
						
							|  |  |  | 								] | 
					
						
							|  |  |  | 							], | 
					
						
							|  |  |  | 							userRemoteConfigs: [ | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 								[name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GERRIT_PROJECT_URL ] | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 							] | 
					
						
							|  |  |  | 						] | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						sh "sudo tests/CI/setupJenkinsEnvironment.sh" | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -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-24 04:39:30 -06:00
										 |  |  | 					def dockerOptions = "--privileged --ulimit core=0 --ulimit nofile=10240 " + | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 						" -v /srv/jenkins:/srv/jenkins:rw -v /srv/cache:/srv/cache:rw " + | 
					
						
							|  |  |  | 						" --entrypoint=''" | 
					
						
							| 
									
										
										
										
											2018-07-16 06:16:51 -06:00
										 |  |  | 					def bt = env.BUILD_TAG.replaceAll(/[^a-zA-Z0-9_.-]/, '-') | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 					def outputdir = "tests/CI/output/Testsuite" | 
					
						
							| 
									
										
										
										
											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() | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					stage ("Build") { | 
					
						
							| 
									
										
										
										
											2018-07-16 06:16:51 -06:00
										 |  |  | 						img.inside(dockerOptions + " --name ${bt}-build") { | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 							echo 'Building..' | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 							env.CCACHE_DIR = "/srv/cache/ccache" | 
					
						
							| 
									
										
										
										
											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 13:00:38 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: false, | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 								artifacts: "${outputdir}/*" | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					def testGroups = readJSON file: "tests/CI/gateTestGroups.json" | 
					
						
							|  |  |  | 					def parallelTasks = [ : ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					for (def testGroup in testGroups) { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 						/* | 
					
						
							|  |  |  | 						 * Because each task is a Groovy closure, we need to | 
					
						
							|  |  |  | 						 * keep local references to some variables. | 
					
						
							|  |  |  | 						 */ | 
					
						
							|  |  |  | 						def groupName = testGroup.name | 
					
						
							|  |  |  | 						def groupDir = testGroup.dir | 
					
						
							|  |  |  | 						def groupTestcmd = testGroup.testcmd | 
					
						
							| 
									
										
										
										
											2018-07-13 05:56:38 -06:00
										 |  |  | 						def testsuiteUrl = env.GERRIT_PROJECT_URL.replaceAll(/\/(Security-)?[^\/]+$/, "/\$1testsuite") | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						parallelTasks[groupName] = { | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 							stage (groupName) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-16 06:16:51 -06:00
										 |  |  | 								img.inside("${dockerOptions} --name ${bt}-${groupName}") { | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 									lock("${JOB_NAME}.${NODE_NAME}.installer") { | 
					
						
							| 
									
										
										
										
											2018-07-25 09:20:20 -06:00
										 |  |  | 										sh "sudo ./tests/CI/installAsterisk.sh --branch-name=${BRANCH_NAME} --user-group=jenkins:users" | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 									} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 13:54:04 -06:00
										 |  |  | 									sh "sudo rm -rf ${groupDir} || : " | 
					
						
							|  |  |  | 									 | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 									checkout scm: [$class: 'GitSCM', | 
					
						
							|  |  |  | 										branches: [[name: "${BRANCH_NAME}"]], | 
					
						
							|  |  |  | 											extensions: [ | 
					
						
							|  |  |  | 												[$class: 'RelativeTargetDirectory', relativeTargetDir: groupDir], | 
					
						
							|  |  |  | 												[$class: 'CloneOption', | 
					
						
							|  |  |  | 													noTags: true, | 
					
						
							|  |  |  | 													depth: 10, | 
					
						
							|  |  |  | 													honorRefspec: true, | 
					
						
							|  |  |  | 													shallow: true | 
					
						
							|  |  |  | 												], | 
					
						
							|  |  |  | 											], | 
					
						
							|  |  |  | 											userRemoteConfigs: [[name: env.GERRIT_NAME, url: testsuiteUrl]] | 
					
						
							|  |  |  | 										] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-23 11:23:22 -04:00
										 |  |  | 									sh "sudo tests/CI/runTestsuite.sh --testsuite-dir='${groupDir}' --testsuite-command='${groupTestcmd}'" | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 									archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: true, | 
					
						
							| 
									
										
										
										
											2018-07-11 13:54:04 -06:00
										 |  |  | 										artifacts: "${groupDir}/asterisk-test-suite-report.xml, ${groupDir}/logs/**, ${groupDir}/core*.txt" | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 13:54:04 -06:00
										 |  |  | 									junit testResults: "${groupDir}/asterisk-test-suite-report.xml", | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 										healthScaleFactor: 1.0, | 
					
						
							|  |  |  | 										keepLongStdio: true | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 									echo "Group result d: ${currentBuild.currentResult}" | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 								echo "Group result s: ${currentBuild.currentResult}" | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					parallel parallelTasks | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	post { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 		cleanup { | 
					
						
							|  |  |  | 			sh "sudo make distclean 2&>/dev/null || : " | 
					
						
							|  |  |  | 			sh "sudo rm -rf tests/CI/output  2&>/dev/null || : " | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -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-12 15:34:14 -06:00
										 |  |  | 		always { | 
					
						
							|  |  |  | 			script { | 
					
						
							|  |  |  | 				def cat | 
					
						
							|  |  |  | 				def comment | 
					
						
							| 
									
										
										
										
											2018-07-16 07:44:25 -06:00
										 |  |  | 				def rvalue | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 				switch (currentBuild.currentResult) { | 
					
						
							|  |  |  | 					case ~/^SUCCESS$/: | 
					
						
							|  |  |  | 						cat = "Passed" | 
					
						
							|  |  |  | 						comment = "" | 
					
						
							| 
									
										
										
										
											2018-07-16 07:44:25 -06:00
										 |  |  | 						rvalue = 2 | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 						break | 
					
						
							|  |  |  | 					case ~/^FAILURE$/: | 
					
						
							|  |  |  | 						cat = "Failed" | 
					
						
							|  |  |  | 						comment = "Fatal Error" | 
					
						
							| 
									
										
										
										
											2018-07-16 07:44:25 -06:00
										 |  |  | 						rvalue = -1 | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 						break | 
					
						
							|  |  |  | 					case ~/^UNSTABLE$/: | 
					
						
							|  |  |  | 						cat = "Failed" | 
					
						
							|  |  |  | 						comment = "Tests Failed" | 
					
						
							| 
									
										
										
										
											2018-07-16 07:44:25 -06:00
										 |  |  | 						rvalue = -1 | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 						break | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-16 07:44:25 -06:00
										 |  |  | 				gerritverificationpublisher verifyStatusValue: rvalue, | 
					
						
							|  |  |  | 					verifyStatusCategory: cat, verifyStatusURL: '', | 
					
						
							|  |  |  | 					verifyStatusComment: comment, verifyStatusName: '', | 
					
						
							|  |  |  | 					verifyStatusReporter: 'Jenkins2', verifyStatusRerun: 'regate' | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 		success { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 			echo "Reporting ${currentBuild.currentResult} Passed" | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		failure { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 			echo "Reporting ${currentBuild.currentResult}: Failed: Fatal Error" | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		unstable { | 
					
						
							| 
									
										
										
										
											2018-07-12 15:34:14 -06:00
										 |  |  | 			echo "Reporting ${currentBuild.currentResult}: Failed: Tests Failed" | 
					
						
							| 
									
										
										
										
											2018-07-11 13:00:38 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |