kitchen-windows2016-py2 7.5 KB

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