CI: Add wiki doc publish to periodics
[asterisk/asterisk.git] / tests / CI / periodics-daily.jenkinsfile
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 delcarative pipeline.
12  */
13 pipeline {
14         triggers {
15                 cron 'H H(0-4) * * *'
16         }
17
18         agent {
19                 /* All of the stages need to be performed on a docker host */
20                 label "swdev-docker"
21         }
22
23         stages {
24                 stage ("->") {
25                         steps {
26                                 /* Here's where we switch to scripted pipeline */
27                                 script {
28                                         stage ("Checkout") {
29                                                 sh "sudo chown -R jenkins:users ."
30                                                 sh "printenv | sort"
31                                                 sh "sudo tests/CI/setupJenkinsEnvironment.sh"
32                                         }
33
34                                         def images = env.DOCKER_IMAGES.split(' ')
35                                         def r = currentBuild.startTimeInMillis % images.length
36                                         def ri = images[(int)r]
37                                         def randomImage = env.DOCKER_REGISTRY + "/" + ri
38                                         def dockerOptions = "--ulimit core=0 --ulimit nofile=10240 " +
39                                                 " -v /srv/jenkins:/srv/jenkins:rw -v /srv/cache:/srv/cache:rw " +
40                                                 " --entrypoint=''"
41                                         def bt = env.BUILD_TAG.replaceAll(/[^a-zA-Z0-9_.-]/, '-')
42                                         def outputdir = "tests/CI/output/Testsuite"
43                                         def img = docker.image(randomImage)
44                                         img.pull()
45
46                                         img.inside(dockerOptions + " --name ${bt}-build") {
47                                                 stage ("Build") {
48                                                         echo 'Building..'
49                                                         env.CCACHE_DIR = "/srv/cache/ccache"
50                                                         sh "./tests/CI/buildAsterisk.sh --output-dir=${outputdir} --cache-dir=/srv/cache"
51
52                                                         archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: false,
53                                                                 artifacts: "${outputdir}/*"
54                                                 }
55                                                 stage ("Docs") {
56
57                                                         sh 'sudo ./tests/CI/installAsterisk.sh  --user-group=jenkins:users'
58
59                                                         def docUrl = env.GIT_URL.replaceAll(/\/[^\/]+$/, "/publish-docs")
60                                                         checkout scm: [$class: 'GitSCM',
61                                                                 branches: [[name: "master"]],
62                                                                         extensions: [
63                                                                                 [$class: 'RelativeTargetDirectory', relativeTargetDir: "tests/CI/output/publish-docs"],
64                                                                                 [$class: 'CloneOption',
65                                                                                         noTags: true,
66                                                                                         depth: 10,
67                                                                                         honorRefspec: true,
68                                                                                         shallow: true
69                                                                                 ],
70                                                                         ],
71                                                                         userRemoteConfigs: [[url: docUrl]]
72                                                                 ]
73
74                                                         sh "./tests/CI/publishAsteriskDocs.sh --branch-name=${BRANCH_NAME} --wiki-doc-branch-regex=\"${WIKI_DOC_BRANCH_REGEX}\""
75                                                 }
76                                         }
77
78                                         def testGroups = readJSON file: "tests/CI/periodic-dailyTestGroups.json"
79                                         def parallelTasks = [ : ]
80
81                                         for (def testGroup in testGroups) {
82                                                 /*
83                                                  * Because each task is a Groovy closure, we need to
84                                                  * keep local references to some variables.
85                                                  */
86                                                 def groupName = testGroup.name
87                                                 def groupDir = testGroup.dir
88                                                 def groupTestcmd = testGroup.testcmd
89                                                 def groupRunTestsuiteOptions = testGroup.runTestsuiteOptions
90                                                 def testsuiteUrl = env.GIT_URL.replaceAll(/\/[^\/]+$/, "/testsuite")
91
92                                                 parallelTasks[groupName] = {
93                                                         stage (groupName) {
94
95                                                                 img.inside("${dockerOptions} --name ${bt}-${groupName}") {
96
97                                                                         lock("${JOB_NAME}.${NODE_NAME}.installer") {
98                                                                                 sh 'sudo ./tests/CI/installAsterisk.sh  --user-group=jenkins:users'
99                                                                         }
100
101                                                                         sh "sudo rm -rf ${groupDir} || : "
102
103                                                                         checkout scm: [$class: 'GitSCM',
104                                                                                 branches: [[name: "${BRANCH_NAME}"]],
105                                                                                         extensions: [
106                                                                                                 [$class: 'RelativeTargetDirectory', relativeTargetDir: groupDir],
107                                                                                                 [$class: 'CloneOption',
108                                                                                                         noTags: true,
109                                                                                                         depth: 10,
110                                                                                                         honorRefspec: true,
111                                                                                                         shallow: true
112                                                                                                 ],
113                                                                                         ],
114                                                                                         userRemoteConfigs: [[url: testsuiteUrl]]
115                                                                                 ]
116
117                                                                         sh "sudo tests/CI/runTestsuite.sh ${groupRunTestsuiteOptions} --testsuite-dir='${groupDir}' --test-command='${groupTestcmd}'"
118
119                                                                         archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: true,
120                                                                                 artifacts: "${groupDir}/asterisk-test-suite-report.xml, ${groupDir}/logs/**, ${groupDir}/core*.txt"
121
122                                                                         junit testResults: "${groupDir}/asterisk-test-suite-report.xml",
123                                                                                 healthScaleFactor: 1.0,
124                                                                                 keepLongStdio: true
125
126                                                                         echo "Group result d: ${currentBuild.currentResult}"
127                                                                 }
128                                                                 echo "Group result s: ${currentBuild.currentResult}"
129                                                         }
130                                                 }
131                                         }
132                                         parallel parallelTasks
133                                 }
134                         }
135                 }
136         }
137         post {
138                 cleanup {
139                         sh "sudo make distclean 2&>/dev/null || : "
140                         sh "sudo rm -rf tests/CI/output  2&>/dev/null || : "
141                 }
142                 success {
143                         echo "Reporting ${currentBuild.currentResult} Passed"
144                 }
145                 failure {
146                         echo "Reporting ${currentBuild.currentResult}: Failed: Fatal Error"
147                 }
148                 unstable {
149                         echo "Reporting ${currentBuild.currentResult}: Failed: Tests Failed"
150                 }
151         }
152 }