1
0

kitchen-fedora29-py3 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. @Library('salt@1.1') _
  2. // Define the maximum time, in hours, that a test run should run for
  3. def testrun_timeout = 6
  4. // Now define a global pipeline timeout. This is the test run timeout with one(1) additional
  5. // hour to allow for artifacts to be downloaded, if possible.
  6. def global_timeout = testrun_timeout + 1;
  7. def distro_name = 'fedora'
  8. def distro_version = '29'
  9. def python_version = 'py3'
  10. def test_transport = 'ZeroMQ'
  11. def salt_target_branch = '2018.3'
  12. def golden_images_branch = '2018.3'
  13. def nox_passthrough_opts = '--ssh-tests'
  14. properties([
  15. buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')),
  16. parameters([
  17. booleanParam(defaultValue: true, description: 'Run full test suite', name: 'runFull')
  18. ])
  19. ])
  20. // Be sure to cancel any previously running builds
  21. def buildNumber = env.BUILD_NUMBER as int
  22. if (buildNumber > 1) {
  23. // This will cancel the previous build which also defined a matching milestone
  24. milestone(buildNumber - 1)
  25. }
  26. // Define a milestone for this build so that, if another build starts, this one will be aborted
  27. milestone(buildNumber)
  28. wrappedNode('kitchen-slave', global_timeout, '#jenkins-prod-pr') {
  29. withEnv([
  30. 'SALT_KITCHEN_PLATFORMS=/var/jenkins/workspace/nox-platforms.yml',
  31. 'SALT_KITCHEN_VERIFIER=/var/jenkins/workspace/nox-verifier.yml',
  32. 'SALT_KITCHEN_DRIVER=/var/jenkins/workspace/driver.yml',
  33. "NOX_ENV_NAME=runtests-${test_transport.toLowerCase()}",
  34. 'NOX_ENABLE_FROM_FILENAMES=true',
  35. "NOX_PASSTHROUGH_OPTS=${nox_passthrough_opts}",
  36. "SALT_TARGET_BRANCH=${salt_target_branch}",
  37. "GOLDEN_IMAGES_CI_BRANCH=${golden_images_branch}",
  38. "CODECOV_FLAGS=${distro_name}${distro_version},${python_version},${test_transport.toLowerCase()}",
  39. 'PATH=~/.rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin',
  40. 'RBENV_VERSION=2.6.3',
  41. "TEST_SUITE=${python_version}",
  42. "TEST_PLATFORM=${distro_name}-${distro_version}",
  43. "TEST_TRANSPORT=${test_transport}",
  44. "FORCE_FULL=${params.runFull}",
  45. ]) {
  46. // Checkout the repo
  47. stage('Clone') {
  48. cleanWs notFailBuild: true
  49. checkout scm
  50. sh 'git fetch --no-tags https://github.com/saltstack/salt.git +refs/heads/${SALT_TARGET_BRANCH}:refs/remotes/origin/${SALT_TARGET_BRANCH}'
  51. }
  52. // Setup the kitchen required bundle
  53. stage('Setup') {
  54. sh 'bundle install --with ec2 windows --without docker macos opennebula vagrant'
  55. }
  56. stage('Create VM') {
  57. retry(3) {
  58. sh '''
  59. t=$(shuf -i 30-120 -n 1); echo "Sleeping $t seconds"; sleep $t
  60. bundle exec kitchen create $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?";
  61. '''
  62. sh """
  63. if [ -s ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ]; then
  64. mv ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ".kitchen/logs/${python_version}-${distro_name}-${distro_version}-create.log"
  65. fi
  66. if [ -s ".kitchen/logs/kitchen.log" ]; then
  67. mv ".kitchen/logs/kitchen.log" ".kitchen/logs/kitchen-create.log"
  68. fi
  69. """
  70. }
  71. }
  72. sshagent(credentials: ['jenkins-testing-ssh-key']) {
  73. sh 'ssh-add ~/.ssh/kitchen.pem'
  74. try {
  75. timeout(time: testrun_timeout, unit: 'HOURS') {
  76. stage('Converge VM') {
  77. sh 'bundle exec kitchen converge $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?";'
  78. sh """
  79. if [ -s ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ]; then
  80. mv ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ".kitchen/logs/${python_version}-${distro_name}-${distro_version}-converge.log"
  81. fi
  82. if [ -s ".kitchen/logs/kitchen.log" ]; then
  83. mv ".kitchen/logs/kitchen.log" ".kitchen/logs/kitchen-converge.log"
  84. fi
  85. """
  86. }
  87. stage('Run Tests') {
  88. withEnv(["DONT_DOWNLOAD_ARTEFACTS=1"]) {
  89. sh 'bundle exec kitchen verify $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?";'
  90. }
  91. }
  92. }
  93. } finally {
  94. try {
  95. sh """
  96. if [ -s ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ]; then
  97. mv ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ".kitchen/logs/${python_version}-${distro_name}-${distro_version}-verify.log"
  98. fi
  99. if [ -s ".kitchen/logs/kitchen.log" ]; then
  100. mv ".kitchen/logs/kitchen.log" ".kitchen/logs/kitchen-verify.log"
  101. fi
  102. """
  103. stage('Download Artefacts') {
  104. withEnv(["ONLY_DOWNLOAD_ARTEFACTS=1"]){
  105. sh '''
  106. bundle exec kitchen verify $TEST_SUITE-$TEST_PLATFORM || exit 0
  107. '''
  108. }
  109. sh """
  110. if [ -s ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ]; then
  111. mv ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ".kitchen/logs/${python_version}-${distro_name}-${distro_version}-download.log"
  112. fi
  113. if [ -s ".kitchen/logs/kitchen.log" ]; then
  114. mv ".kitchen/logs/kitchen.log" ".kitchen/logs/kitchen-download.log"
  115. fi
  116. """
  117. }
  118. archiveArtifacts(
  119. artifacts: "artifacts/*,artifacts/**/*,.kitchen/logs/*-create.log,.kitchen/logs/*-converge.log,.kitchen/logs/*-verify.log,.kitchen/logs/*-download.log,artifacts/xml-unittests-output/*.xml",
  120. allowEmptyArchive: true
  121. )
  122. junit 'artifacts/xml-unittests-output/*.xml'
  123. } finally {
  124. stage('Cleanup') {
  125. sh '''
  126. bundle exec kitchen destroy $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?";
  127. '''
  128. }
  129. stage('Upload Coverage') {
  130. script {
  131. withCredentials([[$class: 'StringBinding', credentialsId: 'codecov-upload-token-salt', variable: 'CODECOV_TOKEN']]) {
  132. sh '''
  133. if [ -n "${FORCE_FULL}" -a "${FORCE_FULL}" = "true" -a -f artifacts/coverage/coverage.xml ]; then
  134. (curl -L https://codecov.io/bash | /bin/sh -s -- -R $(pwd) -s artifacts/coverage/ -F "${CODECOV_FLAGS}") || true
  135. fi
  136. '''
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. // vim: ft=groovy