|
| 1 | +pipeline { |
| 2 | + agent any |
| 3 | + options { |
| 4 | + // Running builds concurrently could cause a race condition with |
| 5 | + // building the Docker image. |
| 6 | + disableConcurrentBuilds() |
| 7 | + buildDiscarder(logRotator(numToKeepStr: '5')) |
| 8 | + lock resource: 'VoightKampff' |
| 9 | + } |
| 10 | + stages { |
| 11 | + // Run the build in the against the dev branch to check for compile errors |
| 12 | + stage('Run Integration Tests') { |
| 13 | + when { |
| 14 | + anyOf { |
| 15 | + branch 'dev' |
| 16 | + branch 'master' |
| 17 | + changeRequest target: 'dev' |
| 18 | + } |
| 19 | + } |
| 20 | + environment { |
| 21 | + // Some branches have a "/" in their name (e.g. feature/new-and-cool) |
| 22 | + // Some commands, such as those tha deal with directories, don't |
| 23 | + // play nice with this naming convention. Define an alias for the |
| 24 | + // branch name that can be used in these scenarios. |
| 25 | + BRANCH_ALIAS = sh( |
| 26 | + script: 'echo $BRANCH_NAME | sed -e "s#/#-#g"', |
| 27 | + returnStdout: true |
| 28 | + ).trim() |
| 29 | + } |
| 30 | + steps { |
| 31 | + echo 'Building Mark I Voight-Kampff Docker Image' |
| 32 | + sh 'cp test/Dockerfile.test Dockerfile' |
| 33 | + sh 'docker build \ |
| 34 | + --target voight_kampff_builder \ |
| 35 | + --build-arg platform=mycroft_mark_1 \ |
| 36 | + -t voight-kampff-mark-1:${BRANCH_ALIAS} .' |
| 37 | + echo 'Running Mark I Voight-Kampff Test Suite' |
| 38 | + timeout(time: 60, unit: 'MINUTES') |
| 39 | + { |
| 40 | + sh 'docker run \ |
| 41 | + -v "$HOME/voight-kampff/identity:/root/.mycroft/identity" \ |
| 42 | + -v "$HOME/voight-kampff/:/root/allure" \ |
| 43 | + voight-kampff-mark-1:${BRANCH_ALIAS} \ |
| 44 | + -f allure_behave.formatter:AllureFormatter \ |
| 45 | + -o /root/allure/allure-result --tags ~@xfail' |
| 46 | + } |
| 47 | + } |
| 48 | + post { |
| 49 | + always { |
| 50 | + echo 'Report Test Results' |
| 51 | + echo 'Changing ownership...' |
| 52 | + sh 'docker run \ |
| 53 | + -v "$HOME/voight-kampff/:/root/allure" \ |
| 54 | + --entrypoint=/bin/bash \ |
| 55 | + voight-kampff-mark-1:${BRANCH_ALIAS} \ |
| 56 | + -x -c "chown $(id -u $USER):$(id -g $USER) \ |
| 57 | + -R /root/allure/"' |
| 58 | + |
| 59 | + echo 'Transferring...' |
| 60 | + sh 'rm -rf allure-result/*' |
| 61 | + sh 'mv $HOME/voight-kampff/allure-result allure-result' |
| 62 | + script { |
| 63 | + allure([ |
| 64 | + includeProperties: false, |
| 65 | + jdk: '', |
| 66 | + properties: [], |
| 67 | + reportBuildPolicy: 'ALWAYS', |
| 68 | + results: [[path: 'allure-result']] |
| 69 | + ]) |
| 70 | + } |
| 71 | + unarchive mapping:['allure-report.zip': 'allure-report.zip'] |
| 72 | + sh ( |
| 73 | + label: 'Publish Report to Web Server', |
| 74 | + script: '''scp allure-report.zip [email protected]:~; |
| 75 | + ssh [email protected] "unzip -o ~/allure-report.zip"; |
| 76 | + ssh [email protected] "rm -rf /var/www/voight-kampff/core/${BRANCH_ALIAS}"; |
| 77 | + ssh [email protected] "mv allure-report /var/www/voight-kampff/core/${BRANCH_ALIAS}" |
| 78 | + ''' |
| 79 | + ) |
| 80 | + echo 'Report Published' |
| 81 | + } |
| 82 | + failure { |
| 83 | + script { |
| 84 | + // Create comment for Pull Requests |
| 85 | + if (env.CHANGE_ID) { |
| 86 | + echo 'Sending PR comment' |
| 87 | + pullRequest.comment('Voight Kampff Integration Test Failed ([Results](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '))') |
| 88 | + } |
| 89 | + } |
| 90 | + // Send failure email containing a link to the Jenkins build |
| 91 | + // the results report and the console log messages to Mycroft |
| 92 | + // developers, the developers of the pull request and the |
| 93 | + // developers that caused the build to fail. |
| 94 | + echo 'Sending Failure Email' |
| 95 | + emailext ( |
| 96 | + attachLog: true, |
| 97 | + subject: "FAILED - Core Integration Tests - Build ${BRANCH_NAME} #${BUILD_NUMBER}", |
| 98 | + body: """ |
| 99 | + <p> |
| 100 | + One or more integration tests failed. Use the |
| 101 | + resources below to identify the issue and fix |
| 102 | + the failing tests. |
| 103 | + </p> |
| 104 | + <br> |
| 105 | + <p> |
| 106 | + <a href='${BUILD_URL}'> |
| 107 | + Jenkins Build Details |
| 108 | + </a> |
| 109 | +  (Requires account on Mycroft's Jenkins instance) |
| 110 | + </p> |
| 111 | + <br> |
| 112 | + <p> |
| 113 | + <a href='https://reports.mycroft.ai/core/${BRANCH_ALIAS}'> |
| 114 | + Report of Test Results |
| 115 | + </a> |
| 116 | + </p> |
| 117 | + <br> |
| 118 | + <p>Console log is attached.</p>""", |
| 119 | + |
| 120 | + |
| 121 | + recipientProviders: [ |
| 122 | + [$class: 'RequesterRecipientProvider'], |
| 123 | + [$class:'CulpritsRecipientProvider'], |
| 124 | + [$class:'DevelopersRecipientProvider'] |
| 125 | + ] |
| 126 | + ) |
| 127 | + } |
| 128 | + success { |
| 129 | + script { |
| 130 | + if (env.CHANGE_ID) { |
| 131 | + echo 'Sending PR comment' |
| 132 | + pullRequest.comment('Voight Kampff Integration Test Succeeded ([Results](https://reports.mycroft.ai/core/' + env.BRANCH_ALIAS + '))') |
| 133 | + } |
| 134 | + } |
| 135 | + // Send success email containing a link to the Jenkins build |
| 136 | + // and the results report to Mycroft developers, the developers |
| 137 | + // of the pull request and the developers that caused the |
| 138 | + // last failed build. |
| 139 | + echo 'Sending Success Email' |
| 140 | + emailext ( |
| 141 | + subject: "SUCCESS - Core Integration Tests - Build ${BRANCH_NAME} #${BUILD_NUMBER}", |
| 142 | + body: """ |
| 143 | + <p> |
| 144 | + All integration tests passed. No further action required. |
| 145 | + </p> |
| 146 | + <br> |
| 147 | + <p> |
| 148 | + <a href='${BUILD_URL}'> |
| 149 | + Jenkins Build Details |
| 150 | + </a> |
| 151 | +  (Requires account on Mycroft's Jenkins instance) |
| 152 | + </p> |
| 153 | + <br> |
| 154 | + <p> |
| 155 | + <a href='https://reports.mycroft.ai/core/${BRANCH_ALIAS}'> |
| 156 | + Report of Test Results |
| 157 | + </a> |
| 158 | + </p>""", |
| 159 | + |
| 160 | + |
| 161 | + recipientProviders: [ |
| 162 | + [$class: 'RequesterRecipientProvider'], |
| 163 | + [$class:'CulpritsRecipientProvider'], |
| 164 | + [$class:'DevelopersRecipientProvider'] |
| 165 | + ] |
| 166 | + ) |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + // Build a voight_kampff image for major releases. This will be used |
| 171 | + // by the mycroft-skills repository to test skill changes. Skills are |
| 172 | + // tested against major releases to determine if they play nicely with |
| 173 | + // the breaking changes included in said release. |
| 174 | + stage('Build Major Release Image') { |
| 175 | + when { |
| 176 | + tag "release/v*.*.0" |
| 177 | + } |
| 178 | + environment { |
| 179 | + // Tag name is usually formatted like "20.2.0" whereas skill |
| 180 | + // branch names are usually "20.02". Reformat the tag name |
| 181 | + // to the skill branch format so this image will be easy to find |
| 182 | + // in the mycroft-skill repository. |
| 183 | + SKILL_BRANCH = sh( |
| 184 | + script: 'echo $TAG_NAME | sed -e "s/v//g" -e "s/[.]0//g" -e "s/[.]/.0/g"', |
| 185 | + returnStdout: true |
| 186 | + ).trim() |
| 187 | + } |
| 188 | + steps { |
| 189 | + echo 'Building ${TAG_NAME} Docker Image for Skill Testing' |
| 190 | + sh 'cp test/Dockerfile.test Dockerfile' |
| 191 | + sh 'docker build \ |
| 192 | + --target voight_kampff_builder \ |
| 193 | + --build-arg platform=mycroft_mark_1 \ |
| 194 | + -t voight-kampff-mark-1:${SKILL_BRANCH} .' |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | + post { |
| 199 | + cleanup { |
| 200 | + sh( |
| 201 | + label: 'Docker Container and Image Cleanup', |
| 202 | + script: ''' |
| 203 | + docker container prune --force; |
| 204 | + docker image prune --force; |
| 205 | + ''' |
| 206 | + ) |
| 207 | + } |
| 208 | + } |
| 209 | +} |
0 commit comments