kitchen-windows2016-py2 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Define the maximum time, in hours, that a test run should run for
  2. def testrun_timeout = 8
  3. // Now define a global pipeline timeout. This is the test run timeout with one(1) additional
  4. // hour to allow for artifacts to be downloaded, if possible.
  5. def global_timeout = testrun_timeout + 1;
  6. def distro_name = 'windows'
  7. def distro_version = '2016'
  8. def python_version = 'py2'
  9. def salt_target_branch = '2019.2'
  10. def golden_images_branch = '2019.2'
  11. properties([
  12. buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')),
  13. parameters([
  14. booleanParam(defaultValue: false, description: 'Run full test suite', name: 'runFull')
  15. ])
  16. ])
  17. node('kitchen-slave') {
  18. timeout(time: global_timeout, unit: 'HOURS') {
  19. withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',
  20. accessKeyVariable: 'AWS_ACCESS_KEY_ID',
  21. credentialsId: 'AWS_ACCESS_KEY_ID',
  22. secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
  23. ansiColor('xterm') {
  24. timestamps {
  25. withEnv([
  26. 'SALT_KITCHEN_PLATFORMS=/var/jenkins/workspace/platforms.yml',
  27. 'SALT_KITCHEN_VERIFIER=/var/jenkins/workspace/verifier.yml',
  28. 'SALT_KITCHEN_DRIVER=/var/jenkins/workspace/driver.yml',
  29. 'NOX_ENV_NAME=runtests-zeromq',
  30. 'NOX_ENABLE_FROM_FILENAMES=true',
  31. 'NOX_PASSTHROUGH_OPTS=--ssh-tests',
  32. "SALT_TARGET_BRANCH=${salt_target_branch}",
  33. "GOLDEN_IMAGES_CI_BRANCH=${golden_images_branch}",
  34. "CODECOV_FLAGS=${distro_name}${distro_version},${python_version}",
  35. 'PATH=~/.rbenv/shims:/usr/local/rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin',
  36. 'RBENV_VERSION=2.6.3',
  37. "TEST_SUITE=${python_version}",
  38. "TEST_PLATFORM=${distro_name}-${distro_version}",
  39. "FORCE_FULL=${params.runFull}",
  40. ]) {
  41. // Set the GH status even before cloning the repo
  42. if (env.NODE_NAME.startsWith('jenkins-pr-')) {
  43. stage('github-pending') {
  44. githubNotify credentialsId: 'test-jenkins-credentials',
  45. description: "running ${TEST_SUITE}-${TEST_PLATFORM}...",
  46. status: 'PENDING',
  47. context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
  48. }
  49. }
  50. // Checkout the repo
  51. stage('checkout-scm') {
  52. cleanWs notFailBuild: true
  53. checkout scm
  54. sh 'git fetch --no-tags https://github.com/saltstack/salt.git +refs/heads/${SALT_TARGET_BRANCH}:refs/remotes/origin/${SALT_TARGET_BRANCH}'
  55. }
  56. // Setup the kitchen required bundle
  57. stage('setup-bundle') {
  58. sh 'bundle install --with ec2 windows --without docker macos opennebula vagrant'
  59. }
  60. stage('Create VM') {
  61. retry(3) {
  62. sh '''
  63. t=$(shuf -i 30-120 -n 1); echo "Sleeping $t seconds"; sleep $t
  64. bundle exec kitchen create $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?;"
  65. '''
  66. }
  67. }
  68. try {
  69. sshagent(credentials: ['jenkins-testing-ssh-key']) {
  70. sh 'ssh-add ~/.ssh/jenkins-testing.pem || ssh-add ~/.ssh/kitchen.pem'
  71. try {
  72. timeout(time: testrun_timeout, unit: 'HOURS') {
  73. stage('Converge VM') {
  74. sh 'bundle exec kitchen converge $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?";'
  75. }
  76. stage('Run Tests') {
  77. sh 'bundle exec kitchen verify $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?";'
  78. }
  79. }
  80. } finally {
  81. try {
  82. archiveArtifacts artifacts: 'artifacts/*,artifacts/**/*'
  83. junit 'artifacts/xml-unittests-output/*.xml'
  84. } finally {
  85. stage('Cleanup') {
  86. sh '''
  87. bundle exec kitchen destroy $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?;"
  88. '''
  89. }
  90. stage('Upload Coverage') {
  91. script {
  92. withCredentials([[$class: 'StringBinding', credentialsId: 'codecov-upload-token-salt', variable: 'CODECOV_TOKEN']]) {
  93. sh '''
  94. if [ -n "${FORCE_FULL}" -a "${FORCE_FULL}" = "true" -a -f artifacts/coverage/coverage.xml ]; then
  95. curl -L https://codecov.io/bash | /bin/sh -s -- -R $(pwd) -s artifacts/coverage/ -F "${CODECOV_FLAGS}"
  96. fi
  97. '''
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }
  104. } catch (Exception e) {
  105. currentBuild.result = 'FAILURE'
  106. } finally {
  107. cleanWs notFailBuild: true
  108. if (currentBuild.resultIsBetterOrEqualTo('SUCCESS')) {
  109. if (env.NODE_NAME.startsWith('jenkins-pr-')) {
  110. githubNotify credentialsId: 'test-jenkins-credentials',
  111. description: "The ${TEST_SUITE}-${TEST_PLATFORM} job has passed",
  112. status: 'SUCCESS',
  113. context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
  114. }
  115. } else {
  116. if (env.NODE_NAME.startsWith('jenkins-pr-')) {
  117. githubNotify credentialsId: 'test-jenkins-credentials',
  118. description: "The ${TEST_SUITE}-${TEST_PLATFORM} job has failed",
  119. status: 'FAILURE',
  120. context: "jenkins/pr/${TEST_SUITE}-${TEST_PLATFORM}"
  121. }
  122. try {
  123. slackSend channel: "#jenkins-prod-pr",
  124. color: '#FF0000',
  125. message: "FAILED: PR-Job: '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
  126. } catch (Exception e) {
  127. sh 'echo Failed to send the Slack notification'
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }
  137. // vim: ft=groovy