ref_debug.jenkinsfile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 delcarative 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. pipeline {
  21. options {
  22. timestamps()
  23. timeout(time: timeoutTime, unit: timeoutUnits)
  24. }
  25. triggers {
  26. cron 'H H(0-4) * * 0'
  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. stage ("Build") {
  56. img.inside(dockerOptions + " --name ${bt}-build") {
  57. echo 'Building..'
  58. env.CCACHE_DIR = "/srv/cache/ccache"
  59. sh "./tests/CI/buildAsterisk.sh --ref-debug --branch-name=${BRANCH_NAME} --output-dir=${outputdir} --cache-dir=/srv/cache"
  60. archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: false,
  61. artifacts: "${outputdir}/*"
  62. }
  63. }
  64. def testGroups = readJSON file: "tests/CI/ref_debugTestGroups.json"
  65. def parallelTasks = [ : ]
  66. for (def testGroup in testGroups) {
  67. /*
  68. * Because each task is a Groovy closure, we need to
  69. * keep local references to some variables.
  70. */
  71. def groupName = testGroup.name
  72. def groupDir = testGroup.dir
  73. def groupTestcmd = testGroup.testcmd
  74. def testsuiteUrl = env.GIT_URL.replaceAll(/\/[^\/]+$/, "/testsuite")
  75. parallelTasks[groupName] = {
  76. stage (groupName) {
  77. img.inside("${dockerOptions} --name ${bt}-${groupName}") {
  78. lock("${JOB_NAME}.${NODE_NAME}.installer") {
  79. sh "sudo ./tests/CI/installAsterisk.sh --uninstall-all --branch-name=${BRANCH_NAME} --user-group=jenkins:users"
  80. }
  81. sh "sudo rm -rf ${groupDir} || : "
  82. checkout scm: [$class: 'GitSCM',
  83. branches: [[name: "${BRANCH_NAME}"]],
  84. extensions: [
  85. [$class: 'RelativeTargetDirectory', relativeTargetDir: groupDir],
  86. [$class: 'CloneOption',
  87. noTags: true,
  88. depth: 10,
  89. honorRefspec: true,
  90. shallow: true
  91. ],
  92. ],
  93. userRemoteConfigs: [[url: testsuiteUrl]]
  94. ]
  95. sh "sudo tests/CI/runTestsuite.sh --testsuite-dir='${groupDir}' --testsuite-command='${groupTestcmd}'"
  96. archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: true,
  97. artifacts: "${groupDir}/asterisk-test-suite-report.xml, ${groupDir}/logs/**, ${groupDir}/core*.txt"
  98. junit testResults: "${groupDir}/asterisk-test-suite-report.xml",
  99. healthScaleFactor: 1.0,
  100. keepLongStdio: true
  101. }
  102. }
  103. }
  104. }
  105. parallel parallelTasks
  106. }
  107. }
  108. }
  109. }
  110. post {
  111. cleanup {
  112. sh "sudo make distclean >/dev/null 2>&1 || : "
  113. sh "sudo rm -rf tests/CI/output >/dev/null 2>&1 || : "
  114. }
  115. success {
  116. echo "Reporting ${currentBuild.currentResult} Passed"
  117. }
  118. failure {
  119. echo "Reporting ${currentBuild.currentResult}: Failed: Fatal Error"
  120. }
  121. unstable {
  122. echo "Reporting ${currentBuild.currentResult}: Failed: Tests Failed"
  123. }
  124. }
  125. }