periodics-daily.jenkinsfile 5.6 KB

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