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