-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathpipeline-salt-shaker.groovy
More file actions
134 lines (125 loc) · 8.63 KB
/
pipeline-salt-shaker.groovy
File metadata and controls
134 lines (125 loc) · 8.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def run(params) {
timestamps {
// Init path env variables
env.resultdir = "${WORKSPACE}/results"
env.resultdirbuild = "${resultdir}/${BUILD_NUMBER}"
// The junit plugin doesn't affect full paths
junit_resultdir = "results/${BUILD_NUMBER}/results_junit"
String tf_file = 'susemanager-ci/terracumber_config/tf_files/templates/salt-shaker.tf'
String tfvariables_file = 'susemanager-ci/terracumber_config/tf_files/variables/salt-shaker.tf'
String tfvars_file = 'susemanager-ci/terracumber_config/tf_files/tfvars/salt-shaker/salt-shaker.tfvars'
GString common_params = "--outputdir ${resultdir} --tf ${tf_file} --tf_variables_description_file ${tfvariables_file} --gitfolder ${resultdir}/sumaform --terraform-bin ${params.bin_path}"
if (params.deploy_parallelism) {
common_params = "${common_params} --parallelism ${params.deploy_parallelism}"
}
// Start pipeline
deployed = false
try {
stage('Clone terracumber, susemanager-ci and sumaform') {
// Create a directory for to place the directory with the build results (if it does not exist)
sh "mkdir -p ${resultdir}"
git url: params.terracumber_gitrepo, branch: params.terracumber_ref
dir("susemanager-ci") {
checkout scm
}
// Clone sumaform
sh "set +x; source /home/jenkins/.credentials set -x; ./terracumber-cli ${common_params} --gitrepo ${params.sumaform_gitrepo} --gitref ${params.sumaform_ref} --runstep gitsync"
// Restore Terraform states from artifacts
if (params.use_previous_terraform_state) {
copyArtifacts projectName: currentBuild.projectName, selector: specific("${currentBuild.previousBuild.number}")
}
}
stage('Deploy') {
// Provision the environment
String TERRAFORM_INIT = ''
if (params.terraform_init) {
TERRAFORM_INIT = '--init'
}
String TERRAFORM_TAINT = ''
if (params.terraform_taint) {
switch(params.sumaform_backend) {
case "libvirt":
TERRAFORM_TAINT = " --taint '.*(domain|combustion_disk|cloudinit_disk|ignition_disk|main_disk|data_disk|database_disk|standalone_provisioning).*'";
break;
case "aws":
TERRAFORM_TAINT = " --taint '.*(host).*'";
break;
default:
println("ERROR: Unknown backend ${params.sumaform_backend}");
sh "exit 1";
break;
}
}
// Write the tfvars file and append the selected environment key
sh "rm -f ${resultdir}/sumaform/terraform.tfvars"
sh "cat ${tfvars_file} >> ${resultdir}/sumaform/terraform.tfvars"
sh "echo 'ENVIRONMENT = \"${params.minion}\"' >> ${resultdir}/sumaform/terraform.tfvars"
retry(count: 3) {
sh "set +x; source /home/jenkins/.credentials set -x; export TERRAFORM=${params.bin_path}; export TERRAFORM_PLUGINS=${params.bin_plugins_path}; ./terracumber-cli ${common_params} --logfile ${resultdirbuild}/sumaform.log ${TERRAFORM_INIT} ${TERRAFORM_TAINT} --sumaform-backend ${params.sumaform_backend} --runstep provision"
deployed = true
if (params.wait_after_deploy) {
echo "Waiting ${params.wait_after_deploy} seconds after sumaform deployment (usually to allow transactional system to reboot)"
sh "sleep ${params.wait_after_deploy}"
}
}
}
stage('Salt Shaker testsuite - Unit tests') {
if (!params.run_unit_tests) {
echo "Skipping unit tests as they were not selected for this execution"
return
}
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
if (!params.testsuite_dir) {
sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep saltshaker --saltshaker-cmd '/usr/bin/salt-test --package-flavor ${params.salt_flavor} --skiplist ${params.skip_list_url} unit -- --core-tests --ssh-tests --slow-tests --run-expensive --run-destructive --junitxml /root/results_junit/junit-report-unit.xml -vvv --color=yes --tb=native'"
} else {
sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep saltshaker --saltshaker-cmd '/usr/bin/salt-test --package-flavor ${params.salt_flavor} --directory ${params.testsuite_dir} --skiplist ${params.skip_list_url} unit -- --core-tests --ssh-tests --slow-tests --run-expensive --run-destructive --junitxml /root/results_junit/junit-report-unit.xml -vvv --color=yes --tb=native'"
}
}
}
stage('Salt Shaker testsuite - Integration tests') {
if (!params.run_integration_tests) {
echo "Skipping integration tests as they were not selected for this execution"
return
}
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
if (!params.testsuite_dir) {
sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep saltshaker --saltshaker-cmd '/usr/bin/salt-test --package-flavor ${params.salt_flavor} --skiplist ${params.skip_list_url} integration -- --core-tests --ssh-tests --slow-tests --run-expensive --run-destructive --junitxml /root/results_junit/junit-report-integration.xml -vvv --color=yes --tb=native'"
} else {
sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep saltshaker --saltshaker-cmd '/usr/bin/salt-test --package-flavor ${params.salt_flavor} --directory ${params.testsuite_dir} --skiplist ${params.skip_list_url} integration -- --core-tests --ssh-tests --slow-tests --run-expensive --run-destructive --junitxml /root/results_junit/junit-report-integration.xml -vvv --color=yes --tb=native'"
}
}
}
stage('Salt Shaker testsuite - Functional tests') {
if (!params.run_functional_tests) {
echo "Skipping functional tests as they were not selected for this execution"
return
}
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
if (!params.testsuite_dir) {
sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep saltshaker --saltshaker-cmd '/usr/bin/salt-test --package-flavor ${params.salt_flavor} --skiplist ${params.skip_list_url} functional -- --core-tests --ssh-tests --slow-tests --run-expensive --run-destructive --junitxml /root/results_junit/junit-report-functional.xml -vvv --color=yes --tb=native'"
} else {
sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep saltshaker --saltshaker-cmd '/usr/bin/salt-test --package-flavor ${params.salt_flavor} --directory ${params.testsuite_dir} --skiplist ${params.skip_list_url} functional -- --core-tests --ssh-tests --slow-tests --run-expensive --run-destructive --junitxml /root/results_junit/junit-report-functional.xml -vvv --color=yes --tb=native'"
}
}
}
}
finally {
stage('Save TF state') {
archiveArtifacts artifacts: "results/sumaform/terraform.tfstate, results/sumaform/.terraform/**/*"
}
stage('Get results') {
def error = 0
if (deployed) {
sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep saltshaker_getresults"
junit allowEmptyResults: true, testResults: "${junit_resultdir}/*.xml"
}
// Send email
sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/mail.log --runstep saltshaker_mail"
// Clean up old results
sh "./clean-old-results -r ${resultdir}"
sh "exit ${error}"
}
}
}
}
return this