|
| 1 | +node('sumaform-cucumber') { |
| 2 | + properties([ |
| 3 | + buildDiscarder(logRotator(numToKeepStr: '1', daysToKeepStr: '1', artifactNumToKeepStr: '1')), |
| 4 | + disableConcurrentBuilds(), |
| 5 | + parameters([ |
| 6 | + string(name: 'cucumber_gitrepo', defaultValue: 'https://github.com/uyuni-project/uyuni.git', description: 'Testsuite Git Repository'), |
| 7 | + string(name: 'cucumber_ref', defaultValue: 'master', description: 'Testsuite Git reference (branch, tag...)'), |
| 8 | + string(name: 'tf_file', defaultValue: 'susemanager-ci/terracumber_config/tf_files/Uyuni-Master-tests-coverage.tf', description: 'Path to the tf file to be used'), |
| 9 | + string(name: 'sumaform_gitrepo', defaultValue: 'https://github.com/uyuni-project/sumaform.git', description: 'Sumaform Git Repository'), |
| 10 | + string(name: 'sumaform_ref', defaultValue: 'master', description: 'Sumaform Git reference (branch, tag...)'), |
| 11 | + choice(name: 'sumaform_backend', choices: ['libvirt', 'aws'], description: 'Sumaform backend to be used (see https://github.com/uyuni-project/sumaform#backend-choice)'), |
| 12 | + choice(name: 'terraform_bin', choices: ['/usr/bin/terraform'], description: 'Terraform binary path'), |
| 13 | + choice(name: 'terraform_bin_plugins', choices: ['/usr/bin'], description: 'Terraform plugins path'), |
| 14 | + string(name: 'terracumber_gitrepo', defaultValue: 'https://github.com/uyuni-project/terracumber.git', description: 'Terracumber Git Repository'), |
| 15 | + string(name: 'terracumber_ref', defaultValue: 'master', description: 'Terracumber Git ref (branch, tag...)'), |
| 16 | + booleanParam(name: 'terraform_init', defaultValue: true, description: 'Call terraform init (needed if modules are added or changes)'), |
| 17 | + booleanParam(name: 'terraform_taint', defaultValue: true, description: 'Call terraform taint (so the resources, except volumes, are recreated)'), |
| 18 | + booleanParam(name: 'use_previous_terraform_state', defaultValue: true, description: 'Use previous Terraform state'), |
| 19 | + booleanParam(name: 'must_deploy', defaultValue: false, description: 'Deploy'), |
| 20 | + choice(name: 'rake_namespace', choices: ['cucumber', 'parallel'], description: 'Choose [parallel] (Clients and some features will run in parallel) or [cucumber] (all sequential)'), |
| 21 | + extendedChoice(name: 'functional_scopes', multiSelectDelimiter: ',', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', visibleItemCount: 30, value: '@scope_smdba,@scope_spacecmd,@scope_spacewalk_utils,@scope_visualization,@scope_notification_message,@scope_virtual_host_manager,@scope_subscription_matching,@scope_formulas,@scope_sp_migration,@scope_cve_audit,@scope_onboarding,@scope_content_lifecycle_management,@scope_res,@scope_recurring_actions,@scope_maintenance_windows,@scope_cluster_management,@scope_building_container_images,@scope_kubernetes_integration,@scope_openscap,@scope_ubuntu,@scope_action_chains,@scope_salt_ssh,@scope_tomcat,@scope_changing_software_channels,@scope_monitoring,@scope_salt,@scope_cobbler,@scope_sumatoolbox,@scope_virtualization,@scope_hub,@scope_retail,@scope_configuration_channels,@scope_content_staging,@scope_proxy,@scope_traditional_client,@scope_xmlrpc,@scope_power_management,@scope_retracted_patches', description: 'Choose the functional scopes that you want to test') |
| 22 | + ]) |
| 23 | + ]) |
| 24 | + |
| 25 | + timestamps { |
| 26 | + // Init path env variables |
| 27 | + env.resultdir = "${WORKSPACE}/results" |
| 28 | + env.resultdirbuild = "${resultdir}/${BUILD_NUMBER}" |
| 29 | + |
| 30 | + // The junit plugin doesn't affect full paths |
| 31 | + junit_resultdir = "results/${BUILD_NUMBER}/results_junit" |
| 32 | + env.common_params = "--outputdir ${resultdir} --tf ${params.tf_file} --gitfolder ${resultdir}/sumaform --terraform-bin ${params.terraform_bin}" |
| 33 | + |
| 34 | + // Start pipeline |
| 35 | + deployed = false |
| 36 | + try { |
| 37 | + stage('Clone terracumber, susemanager-ci and sumaform') { |
| 38 | + // Create a directory for to place the directory with the build results (if it does not exist) |
| 39 | + sh "mkdir -p ${resultdir}" |
| 40 | + git url: params.terracumber_gitrepo, branch: params.terracumber_ref |
| 41 | + dir("susemanager-ci") { |
| 42 | + checkout scm |
| 43 | + } |
| 44 | + // Clone sumaform |
| 45 | + sh "set +x; source /home/jenkins/.credentials set -x; ./terracumber-cli ${common_params} --gitrepo ${params.sumaform_gitrepo} --gitref ${params.sumaform_ref} --runstep gitsync" |
| 46 | + |
| 47 | + // Restore Terraform states from artifacts |
| 48 | + if (params.use_previous_terraform_state) { |
| 49 | + copyArtifacts projectName: currentBuild.projectName, selector: specific("${currentBuild.previousBuild.number}") |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + stage('Deploy') { |
| 54 | + if(params.must_deploy) { |
| 55 | + // Provision the environment |
| 56 | + if (params.terraform_init) { |
| 57 | + env.TERRAFORM_INIT = '--init' |
| 58 | + } else { |
| 59 | + env.TERRAFORM_INIT = '' |
| 60 | + } |
| 61 | + env.TERRAFORM_TAINT = '' |
| 62 | + if (params.terraform_taint) { |
| 63 | + switch(params.sumaform_backend) { |
| 64 | + case "libvirt": |
| 65 | + env.TERRAFORM_TAINT = " --taint '.*(domain|main_disk).*'"; |
| 66 | + break; |
| 67 | + case "aws": |
| 68 | + env.TERRAFORM_TAINT = " --taint '.*(host).*'"; |
| 69 | + break; |
| 70 | + default: |
| 71 | + println("ERROR: Unknown backend ${params.sumaform_backend}"); |
| 72 | + sh "exit 1"; |
| 73 | + break; |
| 74 | + } |
| 75 | + } |
| 76 | + sh "set +x; source /home/jenkins/.credentials set -x; export TF_VAR_CUCUMBER_GITREPO=${params.cucumber_gitrepo}; export TF_VAR_CUCUMBER_BRANCH=${params.cucumber_ref}; export TERRAFORM=${params.terraform_bin}; export TERRAFORM_PLUGINS=${params.terraform_bin_plugins}; ./terracumber-cli ${common_params} --logfile ${resultdirbuild}/sumaform.log ${env.TERRAFORM_INIT} ${env.TERRAFORM_TAINT} --sumaform-backend ${params.sumaform_backend} --runstep provision" |
| 77 | + deployed = true |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + stage('Enable JaCoCo Agent') { |
| 82 | + def url = "https://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.agent/0.8.7/org.jacoco.agent-0.8.7-runtime.jar" |
| 83 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'ssh \$SERVER wget ${url} -O /tmp/jacocoagent.jar'" |
| 84 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'ssh \$SERVER \"sed -i \'s/.\$/\\ -javaagent:\\/tmp\\/jacocoagent.jar=output=tcpserver,address=*,port=6300/\' /etc/sysconfig/tomcat\"'" |
| 85 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'ssh \$SERVER echo '\"' >> /etc/sysconfig/tomcat'" |
| 86 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'ssh \$SERVER systemctl restart tomcat.service'" |
| 87 | + } |
| 88 | + |
| 89 | + stage('Sanity Check') { |
| 90 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'cd /root/spacewalk/testsuite; rake cucumber:sanity_check'" |
| 91 | + } |
| 92 | + |
| 93 | + stage('Core - Setup') { |
| 94 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'cd /root/spacewalk/testsuite; rake cucumber:core'" |
| 95 | + } |
| 96 | + |
| 97 | + stage('Dump Test Coverage results') { |
| 98 | + def url = "https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.7/org.jacoco.cli-0.8.7-nodeps.jar" |
| 99 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'ssh \$SERVER wget ${url} -O /tmp/jacococli.jar'" |
| 100 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'ssh \$SERVER java -jar /tmp/jacococli.jar dump --address localhost --destfile /tmp/jacoco.exec --port 6300 --reset'" |
| 101 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'ssh \$SERVER java -jar jacococli.jar report /tmp/jacoco.exec --html /srv/www/htdocs/pub/jacoco-cucumber-report --xml /srv/www/htdocs/pub/jacoco-cucumber-report.xml --classfiles /srv/tomcat/webapps/rhn/WEB-INF/lib'" |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + finally { |
| 106 | + stage('Save TF state') { |
| 107 | + archiveArtifacts artifacts: "results/sumaform/terraform.tfstate, results/sumaform/.terraform/**/*" |
| 108 | + } |
| 109 | + |
| 110 | + stage('Get results') { |
| 111 | + def error = 0 |
| 112 | + if (deployed) { |
| 113 | + try { |
| 114 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'cd /root/spacewalk/testsuite; rake cucumber:finishing'" |
| 115 | + } catch(Exception ex) { |
| 116 | + println("ERROR: rake cucumber:finishing failed") |
| 117 | + error = 1 |
| 118 | + } |
| 119 | + try { |
| 120 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd 'cd /root/spacewalk/testsuite; rake utils:generate_test_report'" |
| 121 | + } catch(Exception ex) { |
| 122 | + println("ERROR: rake utils:generate_test_repor failed") |
| 123 | + error = 1 |
| 124 | + } |
| 125 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/testsuite.log --runstep getresults" |
| 126 | + publishHTML( target: [ |
| 127 | + allowMissing: true, |
| 128 | + alwaysLinkToLastBuild: false, |
| 129 | + keepAll: true, |
| 130 | + reportDir: "${resultdirbuild}/cucumber_report/", |
| 131 | + reportFiles: 'cucumber_report.html', |
| 132 | + reportName: "TestSuite Report"] |
| 133 | + ) |
| 134 | + junit allowEmptyResults: true, testResults: "${junit_resultdir}/*.xml" |
| 135 | + } |
| 136 | + // Send email |
| 137 | + sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/mail.log --runstep mail" |
| 138 | + // Clean up old results |
| 139 | + sh "./clean-old-results -r ${resultdir}" |
| 140 | + sh "exit ${error}" |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | +} |
0 commit comments