Debian Codegraph @

tests/CI/ref_debug.jenkinsfile

raw
1 /*
2 * This pipeline is the "template" for the Asterisk REF_DEBUG Tests multi-branch
3 * parent job. Jenkins will automatically scan the branches in the "asterisk"
4 * or "Security-asterisk" projects in Gerrit and automatically create a branch-
5 * specific job for each branch it finds this file in.
6 *
7 * This file starts as a declarative pipeline because with a declarative
8 * pipeline, you can define the trigger in the pipeline file. This keeps
9 * everything in one place. We transition to scripted pipeline later on because
10 * we need to dynamically determine which docker image we're going to use and
11 * you can't do that in a declarative pipeline.
12 */
13 def timeoutTime = 24
14 def timeoutUnits = 'HOURS'
15 if (env.TIMEOUT_REF_DEBUG) {
16 def _timeout = env.TIMEOUT_REF_DEBUG.split()
17 timeoutTime = _timeout[0].toInteger()
18 timeoutUnits = _timeout[1]
19 }
20
21 pipeline {
22 options {
23 ansiColor('gnome-terminal')
24 throttle(['asterisk-ref-debug'])
25 timestamps()
26 timeout(time: timeoutTime, unit: timeoutUnits)
27 }
28 triggers {
29 cron 'H H(0-4) * * 0'
30 }
31
32 agent {
33 /* All of the stages need to be performed on a docker host */
34 label "asterisk-ref-debug"
35 }
36
37 stages {
38 stage ("->") {
39 steps {
40 /* Here's where we switch to scripted pipeline */
41 script {
42 manager.createSummary("/plugin/workflow-job/images/48x48/pipelinejob.png").appendText("Docker Host: ${NODE_NAME}", false)
43
44 stage ("Checkout") {
45 sh "sudo chown -R jenkins:users ."
46 sh "printenv -0 | sort -z | tr '\\0' '\\n'"
47 sh "sudo tests/CI/setupJenkinsEnvironment.sh"
48 }
49
50 def images = env.DOCKER_IMAGES.split(' ')
51 def r = currentBuild.startTimeInMillis % images.length
52 def ri = images[(int)r]
53 def randomImage = env.DOCKER_REGISTRY + "/" + ri
54 def dockerOptions = "--privileged --ulimit core=0 --ulimit nofile=10240 " +
55 " --tmpfs /tmp:exec,size=1G -v /srv/jenkins:/srv/jenkins:rw -v /srv/cache:/srv/cache:rw " +
56 " --entrypoint=''"
57 def bt = env.BUILD_TAG.replaceAll(/[^a-zA-Z0-9_.-]/, '-')
58 def outputdir = "tests/CI/output/Testsuite"
59
60 manager.createSummary("/plugin/workflow-job/images/48x48/pipelinejob.png").appendText("Docker Image: ${randomImage}", false)
61 def img = docker.image(randomImage)
62 img.pull()
63
64 stage ("Build") {
65 img.inside(dockerOptions + " --name ${bt}-build") {
66 echo 'Building..'
67 env.CCACHE_DIR = "/srv/cache/ccache"
68 sh "./tests/CI/buildAsterisk.sh --ref-debug --branch-name=${BRANCH_NAME} --output-dir=${outputdir} --cache-dir=/srv/cache"
69
70 archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: false,
71 artifacts: "${outputdir}/*"
72 }
73 }
74
75 def testGroups = readJSON file: "tests/CI/ref_debugTestGroups.json"
76 def parallelTasks = [ : ]
77
78 for (def testGroup in testGroups) {
79 /*
80 * Because each task is a Groovy closure, we need to
81 * keep local references to some variables.
82 */
83 def groupName = testGroup.name
84 def groupDir = testGroup.dir
85 def groupTestcmd = testGroup.testcmd
86 def testsuiteUrl = env.GIT_URL.replaceAll(/\/[^\/]+$/, "/testsuite")
87
88 parallelTasks[groupName] = {
89 stage (groupName) {
90
91 img.inside("${dockerOptions} --name ${bt}-${groupName}") {
92
93 lock("${JOB_NAME}.${NODE_NAME}.installer") {
94 sh "sudo ./tests/CI/installAsterisk.sh --uninstall-all --branch-name=${BRANCH_NAME} --user-group=jenkins:users"
95 }
96
97 sh "sudo rm -rf ${groupDir} || : "
98
99 checkout scm: [$class: 'GitSCM',
100 branches: [[name: "${BRANCH_NAME}"]],
101 extensions: [
102 [$class: 'RelativeTargetDirectory', relativeTargetDir: groupDir],
103 [$class: 'CloneOption',
104 noTags: true,
105 honorRefspec: true,
106 shallow: false
107 ],
108 ],
109 userRemoteConfigs: [[url: testsuiteUrl]]
110 ]
111
112 sh "sudo tests/CI/runTestsuite.sh --testsuite-dir='${groupDir}' --testsuite-command='${groupTestcmd}'"
113
114 archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: true,
115 artifacts: "${groupDir}/asterisk-test-suite-report.xml, ${groupDir}/logs/**, ${groupDir}/core*.txt"
116
117 junit testResults: "${groupDir}/asterisk-test-suite-report.xml",
118 healthScaleFactor: 1.0,
119 keepLongStdio: true
120 }
121 }
122 }
123 }
124 parallel parallelTasks
125 }
126 }
127 }
128 }
129 post {
130 cleanup {
131 script {
132 if (env.CLEANUP_WS_REF_DEBUG.toBoolean()) {
133 cleanWs deleteDirs: true, notFailBuild: false
134 }
135 }
136 }
137 success {
138 echo "Reporting ${currentBuild.currentResult} Passed"
139 }
140 failure {
141 echo "Reporting ${currentBuild.currentResult}: Failed: Fatal Error"
142 }
143 unstable {
144 echo "Reporting ${currentBuild.currentResult}: Failed: Tests Failed"
145 }
146 }
147 }