<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/9601">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">CI: Add Testsuite Gate (same as Unit Test)<br><br>Change-Id: Idb2371f51d085aaf0e408bbcf1c28cc680cfaa47<br>---<br>A CI/gates.jenkinsfile<br>1 file changed, 203 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/01/9601/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/CI/gates.jenkinsfile b/CI/gates.jenkinsfile</span><br><span>new file mode 100644</span><br><span>index 0000000..4f5b4ad</span><br><span>--- /dev/null</span><br><span>+++ b/CI/gates.jenkinsfile</span><br><span>@@ -0,0 +1,203 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This pipeline is the "template" for the Testsuite Unit Tests multi-branch</span><br><span style="color: hsl(120, 100%, 40%);">+ * parent job. Jenkins will automatically scan the branches in the "testsuite"</span><br><span style="color: hsl(120, 100%, 40%);">+ * or "Security-testsuite" projects in Gerrit and automatically create a branch-</span><br><span style="color: hsl(120, 100%, 40%);">+ * specific job for each branch it finds this file in.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file starts as a declarative pipeline because with a declarative</span><br><span style="color: hsl(120, 100%, 40%);">+ * pipeline, you can define the trigger in the pipeline file. This keeps</span><br><span style="color: hsl(120, 100%, 40%);">+ * everything in one place. We transition to scripted pipeline later on because</span><br><span style="color: hsl(120, 100%, 40%);">+ * we need to dynamically determine which docker image we're going to use and</span><br><span style="color: hsl(120, 100%, 40%);">+ * you can't do that in a delcarative pipeline.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+pipeline {</span><br><span style="color: hsl(120, 100%, 40%);">+ triggers {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This trigger will match either the "asterisk" or "Security-asterisk"</span><br><span style="color: hsl(120, 100%, 40%);">+ * projects. The branch is taken from the branch this job was created</span><br><span style="color: hsl(120, 100%, 40%);">+ * for.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ gerrit customUrl: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ commentTextParameterMode: 'PLAIN',</span><br><span style="color: hsl(120, 100%, 40%);">+ commitMessageParameterMode: 'PLAIN',</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritBuildSuccessfulVerifiedValue: 2,</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritBuildFailedVerifiedValue: -1,</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritBuildUnstableVerifiedValue: -1,</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritProjects: [</span><br><span style="color: hsl(120, 100%, 40%);">+ [branches: [[compareType: 'PLAIN', pattern: "${BRANCH_NAME}"]],</span><br><span style="color: hsl(120, 100%, 40%);">+ compareType: 'REG_EXP',</span><br><span style="color: hsl(120, 100%, 40%);">+ disableStrictForbiddenFileVerification: false,</span><br><span style="color: hsl(120, 100%, 40%);">+ pattern: '^(Security-)?testsuite.*'</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ silentMode: false,</span><br><span style="color: hsl(120, 100%, 40%);">+ triggerOnEvents: [</span><br><span style="color: hsl(120, 100%, 40%);">+ commentAddedContains('^regate$'),</span><br><span style="color: hsl(120, 100%, 40%);">+ commentAdded(commentAddedTriggerApprovalValue: '+2', verdictCategory: 'Code-Review'),</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ skipVote: [</span><br><span style="color: hsl(120, 100%, 40%);">+ onFailed: false,</span><br><span style="color: hsl(120, 100%, 40%);">+ onNotBuilt: true,</span><br><span style="color: hsl(120, 100%, 40%);">+ onSuccessful: false,</span><br><span style="color: hsl(120, 100%, 40%);">+ onUnstable: false</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ agent {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* All of the stages need to be performed on a docker host */</span><br><span style="color: hsl(120, 100%, 40%);">+ label "swdev-docker"</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ stages {</span><br><span style="color: hsl(120, 100%, 40%);">+ stage ("->") {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Jenkins will try to automatically rebuild this job when</span><br><span style="color: hsl(120, 100%, 40%);">+ * the jenkinsfile changes but since this job is dependent on</span><br><span style="color: hsl(120, 100%, 40%);">+ * Gerrit, we really don't want to do anything in that case.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ when {</span><br><span style="color: hsl(120, 100%, 40%);">+ not { environment name: 'GERRIT_CHANGE_NUMBER', value: '' }</span><br><span style="color: hsl(120, 100%, 40%);">+ not { environment name: 'GERRIT_EVENT_ACCOUNT_NAME', value: 'Jenkins2' }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ steps {</span><br><span style="color: hsl(120, 100%, 40%);">+ script {</span><br><span style="color: hsl(120, 100%, 40%);">+ stage ("Checkout") {</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "sudo chown -R jenkins:users ."</span><br><span style="color: hsl(120, 100%, 40%);">+ env.GERRIT_PROJECT_URL = env.GERRIT_CHANGE_URL.replaceAll(/\/[0-9]+$/, "/${env.GERRIT_PROJECT}")</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "printenv | sort"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Jenkins has already automatically checked out the base branch</span><br><span style="color: hsl(120, 100%, 40%);">+ * for this change but we now need to check out the change itself</span><br><span style="color: hsl(120, 100%, 40%);">+ * and rebase it on the current base branch. If the rebase fails,</span><br><span style="color: hsl(120, 100%, 40%);">+ * that's an indication to the user that they'll need to sort their</span><br><span style="color: hsl(120, 100%, 40%);">+ * change out.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * The Gerrit Trigger provides all the URLs and refspecs to</span><br><span style="color: hsl(120, 100%, 40%);">+ * check out the change.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ checkout scm: [$class: 'GitSCM',</span><br><span style="color: hsl(120, 100%, 40%);">+ branches: [[name: env.GERRIT_BRANCH ]],</span><br><span style="color: hsl(120, 100%, 40%);">+ extensions: [</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'ScmName', name: env.GERRIT_NAME],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'CleanBeforeCheckout'],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'PreBuildMerge', options: [</span><br><span style="color: hsl(120, 100%, 40%);">+ mergeRemote: env.GERRIT_NAME,</span><br><span style="color: hsl(120, 100%, 40%);">+ fastForwardMode: 'NO_FF',</span><br><span style="color: hsl(120, 100%, 40%);">+ mergeStrategy: 'RECURSIVE',</span><br><span style="color: hsl(120, 100%, 40%);">+ mergeTarget: env.GERRIT_BRANCH]],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'CloneOption',</span><br><span style="color: hsl(120, 100%, 40%);">+ honorRefspec: true,</span><br><span style="color: hsl(120, 100%, 40%);">+ noTags: true,</span><br><span style="color: hsl(120, 100%, 40%);">+ depth: 10,</span><br><span style="color: hsl(120, 100%, 40%);">+ shallow: true</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'PruneStaleBranch'],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'BuildChooserSetting',</span><br><span style="color: hsl(120, 100%, 40%);">+ buildChooser: [$class: 'GerritTriggerBuildChooser']</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ userRemoteConfigs: [</span><br><span style="color: hsl(120, 100%, 40%);">+ [name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GERRIT_PROJECT_URL ]</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "sudo CI/setupJenkinsEnvironment.sh --output-dir=CI/output"</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def images = env.DOCKER_IMAGES.split(' ')</span><br><span style="color: hsl(120, 100%, 40%);">+ def r = currentBuild.startTimeInMillis % images.length</span><br><span style="color: hsl(120, 100%, 40%);">+ def ri = images[(int)r]</span><br><span style="color: hsl(120, 100%, 40%);">+ def randomImage = env.DOCKER_REGISTRY + "/" + ri;</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+ def bt = env.BUILD_TAG.replaceAll(/[^a-zA-Z0-9_.-]/, '-')</span><br><span style="color: hsl(120, 100%, 40%);">+ def dockerOptions = "--ulimit core=0 --ulimit nofile=10240 " +</span><br><span style="color: hsl(120, 100%, 40%);">+ " -v /srv/jenkins:/srv/jenkins:rw -v /srv/cache:/srv/cache:rw " +</span><br><span style="color: hsl(120, 100%, 40%);">+ " --entrypoint='' --name ${bt}-build"</span><br><span style="color: hsl(120, 100%, 40%);">+ def outputDir = "CI/output"</span><br><span style="color: hsl(120, 100%, 40%);">+ def astDir = "${outputDir}/asterisk"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def img = docker.image(randomImage)</span><br><span style="color: hsl(120, 100%, 40%);">+ img.pull()</span><br><span style="color: hsl(120, 100%, 40%);">+ img.inside(dockerOptions) {</span><br><span style="color: hsl(120, 100%, 40%);">+ def asteriskUrl = env.GERRIT_PROJECT_URL.replaceAll(/\/(Security-)?[^\/]+$/, "/\$1asterisk") </span><br><span style="color: hsl(120, 100%, 40%);">+ checkout scm: [$class: 'GitSCM',</span><br><span style="color: hsl(120, 100%, 40%);">+ branches: [[name: "${BRANCH_NAME}"]],</span><br><span style="color: hsl(120, 100%, 40%);">+ extensions: [</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'RelativeTargetDirectory', relativeTargetDir: astDir],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'CloneOption',</span><br><span style="color: hsl(120, 100%, 40%);">+ noTags: true,</span><br><span style="color: hsl(120, 100%, 40%);">+ depth: 10,</span><br><span style="color: hsl(120, 100%, 40%);">+ honorRefspec: true,</span><br><span style="color: hsl(120, 100%, 40%);">+ shallow: true</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ userRemoteConfigs: [[name: env.GERRIT_NAME, url: asteriskUrl]]</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+ stage ('Build') {</span><br><span style="color: hsl(120, 100%, 40%);">+ echo 'Building..'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ sh """</span><br><span style="color: hsl(120, 100%, 40%);">+ cd ${astDir}</span><br><span style="color: hsl(120, 100%, 40%);">+ ./tests/CI/buildAsterisk.sh --output-dir=${env.WORKSPACE}/${outputDir} --cache-dir=/srv/cache</span><br><span style="color: hsl(120, 100%, 40%);">+ sudo ./tests/CI/installAsterisk.sh --user-group=jenkins:users</span><br><span style="color: hsl(120, 100%, 40%);">+ """ </span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ stage ('Test') {</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "./self_test"</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ post {</span><br><span style="color: hsl(120, 100%, 40%);">+ cleanup {</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "sudo make distclean 2&>/dev/null || : "</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "sudo rm -rf CI/output 2&>/dev/null || : "</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * The Gerrit Trigger will automatically post the "Verified" results back</span><br><span style="color: hsl(120, 100%, 40%);">+ * to Gerrit but the verification publisher publishes extra stuff in the</span><br><span style="color: hsl(120, 100%, 40%);">+ * "Code Review" section of the review.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ always {</span><br><span style="color: hsl(120, 100%, 40%);">+ script {</span><br><span style="color: hsl(120, 100%, 40%);">+ def cat</span><br><span style="color: hsl(120, 100%, 40%);">+ def comment</span><br><span style="color: hsl(120, 100%, 40%);">+ def rvalue</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (currentBuild.currentResult) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case ~/^SUCCESS$/:</span><br><span style="color: hsl(120, 100%, 40%);">+ cat = "Passed"</span><br><span style="color: hsl(120, 100%, 40%);">+ comment = ""</span><br><span style="color: hsl(120, 100%, 40%);">+ rvalue = 1</span><br><span style="color: hsl(120, 100%, 40%);">+ break</span><br><span style="color: hsl(120, 100%, 40%);">+ case ~/^FAILURE$/:</span><br><span style="color: hsl(120, 100%, 40%);">+ cat = "Failed"</span><br><span style="color: hsl(120, 100%, 40%);">+ comment = "Fatal Error"</span><br><span style="color: hsl(120, 100%, 40%);">+ rvalue = -1</span><br><span style="color: hsl(120, 100%, 40%);">+ break</span><br><span style="color: hsl(120, 100%, 40%);">+ case ~/^UNSTABLE$/:</span><br><span style="color: hsl(120, 100%, 40%);">+ cat = "Failed"</span><br><span style="color: hsl(120, 100%, 40%);">+ comment = "Tests Failed"</span><br><span style="color: hsl(120, 100%, 40%);">+ rvalue = -1</span><br><span style="color: hsl(120, 100%, 40%);">+ break</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritverificationpublisher verifyStatusValue: rvalue,</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusCategory: cat, verifyStatusURL: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusComment: comment, verifyStatusName: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusReporter: 'Jenkins2', verifyStatusRerun: 'regate'</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ success {</span><br><span style="color: hsl(120, 100%, 40%);">+ echo "Reporting ${currentBuild.currentResult} Passed"</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ failure {</span><br><span style="color: hsl(120, 100%, 40%);">+ echo "Reporting ${currentBuild.currentResult}: Failed: Fatal Error"</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ unstable {</span><br><span style="color: hsl(120, 100%, 40%);">+ echo "Reporting ${currentBuild.currentResult}: Failed: Tests Failed"</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9601">change 9601</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/9601"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Idb2371f51d085aaf0e408bbcf1c28cc680cfaa47 </div>
<div style="display:none"> Gerrit-Change-Number: 9601 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>