Debian Codegraph @

tests/CI/periodics-daily.jenkinsfile

raw
1 /*
2 * This pipeline is the "template" for the Asterisk Periodic 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 = 3
14 def timeoutUnits = 'HOURS'
15 if (env.TIMEOUT_DAILIES) {
16 def _timeout = env.TIMEOUT_DAILIES.split()
17 timeoutTime = _timeout[0].toInteger()
18 timeoutUnits = _timeout[1]
19 }
20
21 pipeline {
22 options {
23 ansiColor('gnome-terminal')
24 throttle(['asterisk-daily'])
25 timestamps()
26 timeout(time: timeoutTime, unit: timeoutUnits)
27 }
28 triggers {
29 cron 'H H(0-4) * * *'
30 }
31
32 agent {
33 /* All of the stages need to be performed on a docker host */
34 label "asterisk-daily"
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 img.inside(dockerOptions + " --name ${bt}-build") {
65 stage ("Build") {
66 echo 'Building..'
67 env.CCACHE_DIR = "/srv/cache/ccache"
68 sh "./tests/CI/buildAsterisk.sh --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 stage ("Docs") {
74
75 sh "sudo ./tests/CI/installAsterisk.sh --branch-name=${BRANCH_NAME} --user-group=jenkins:users"
76
77 def docUrl = env.GIT_URL.replaceAll(/\/[^\/]+$/, "/publish-docs")
78 checkout scm: [$class: 'GitSCM',
79 branches: [[name: "master"]],
80 extensions: [
81 [$class: 'RelativeTargetDirectory', relativeTargetDir: "tests/CI/output/publish-docs"],
82 [$class: 'CloneOption',
83 noTags: true,
84 honorRefspec: true,
85 shallow: false
86 ],
87 ],
88 userRemoteConfigs: [[url: docUrl]]
89 ]
90
91 sh "./tests/CI/publishAsteriskDocs.sh --user-group=jenkins:users --branch-name=${BRANCH_NAME} --wiki-doc-branch-regex=\"${WIKI_DOC_BRANCH_REGEX}\""
92 }
93 }
94
95 def testGroups
96 configFileProvider([configFile(fileId: 'asterisk_daily_test_groups', variable: 'DAILY_TEST_GROUPS')]) {
97 echo "Retrieved config file from ${env.DAILY_TEST_GROUPS}"
98 testGroups = readJSON file: env.DAILY_TEST_GROUPS
99 }
100
101 def parallelTasks = [ : ]
102
103 for (def testGroup in testGroups) {
104 /*
105 * Because each task is a Groovy closure, we need to
106 * keep local references to some variables.
107 */
108 def groupName = testGroup.name
109 def groupDir = testGroup.dir
110 def groupTestcmd = testGroup.testcmd
111 def groupRunTestsuiteOptions = testGroup.runTestsuiteOptions
112 def testsuiteUrl = env.GIT_URL.replaceAll(/\/[^\/]+$/, "/testsuite")
113
114 parallelTasks[groupName] = {
115 stage (groupName) {
116
117 img.inside("${dockerOptions} --name ${bt}-${groupName}") {
118
119 lock("${JOB_NAME}.${NODE_NAME}.installer") {
120 sh "sudo ./tests/CI/installAsterisk.sh --uninstall-all --branch-name=${BRANCH_NAME} --user-group=jenkins:users"
121 }
122
123 sh "sudo rm -rf ${groupDir} || : "
124
125 checkout scm: [$class: 'GitSCM',
126 branches: [[name: "${BRANCH_NAME}"]],
127 extensions: [
128 [$class: 'RelativeTargetDirectory', relativeTargetDir: groupDir],
129 [$class: 'CloneOption',
130 noTags: true,
131 depth: 100,
132 honorRefspec: true,
133 shallow: true
134 ],
135 ],
136 userRemoteConfigs: [[url: testsuiteUrl]]
137 ]
138
139 sh "sudo tests/CI/runTestsuite.sh ${groupRunTestsuiteOptions} --testsuite-dir='${groupDir}' --testsuite-command='${groupTestcmd}'"
140
141 archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: true,
142 artifacts: "${groupDir}/asterisk-test-suite-report.xml, ${groupDir}/logs/**, ${groupDir}/core*.txt"
143
144 junit testResults: "${groupDir}/asterisk-test-suite-report.xml",
145 healthScaleFactor: 1.0,
146 keepLongStdio: true
147
148 echo "Group result d: ${currentBuild.currentResult}"
149 }
150 echo "Group result s: ${currentBuild.currentResult}"
151 }
152 }
153 }
154 parallel parallelTasks
155 }
156 }
157 }
158 }
159 post {
160 cleanup {
161 script {
162 if (env.CLEANUP_WS_DAILIES.toBoolean()) {
163 cleanWs deleteDirs: true, notFailBuild: false
164 }
165 }
166 }
167 success {
168 echo "Reporting ${currentBuild.currentResult} Passed"
169 }
170 failure {
171 echo "Reporting ${currentBuild.currentResult}: Failed: Fatal Error"
172 }
173 unstable {
174 echo "Reporting ${currentBuild.currentResult}: Failed: Tests Failed"
175 }
176 }
177 }