|
| 1 | + |
| 2 | + |
| 3 | +def sendFailEmail(){ |
| 4 | + // modify fail email recipient |
| 5 | + def failRecipient = "lanxin.chen@biomind.ai" |
| 6 | + |
| 7 | + def subject = "FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'" |
| 8 | + def summary = "${subject} (${env.BUILD_URL})" |
| 9 | + def details = """ |
| 10 | + FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]': |
| 11 | + Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL})" |
| 12 | + """ |
| 13 | + emailext( |
| 14 | + to: failRecipient, |
| 15 | + recipientProviders: [culprits()], |
| 16 | + subject: subject, |
| 17 | + body: details |
| 18 | + ) |
| 19 | +} |
| 20 | + |
| 21 | +def notifyBuild(String buildStatus = 'STARTED',stageName) { |
| 22 | + |
| 23 | + // modify build status email recipient |
| 24 | + def buildStatusRecipient = "lanxin.chen@biomind.ai" |
| 25 | + |
| 26 | + // default stauts |
| 27 | + buildStatus = buildStatus ?: 'SUCCESSFUL' |
| 28 | + |
| 29 | + def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'" |
| 30 | + def summary = "${subject} (${env.BUILD_URL})" |
| 31 | + def details = """ |
| 32 | + ${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]': |
| 33 | + Stage: ${stageName} |
| 34 | + Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL})" |
| 35 | + """ |
| 36 | + emailext ( |
| 37 | + subject: subject, |
| 38 | + body: details, |
| 39 | + to: buildStatusRecipient |
| 40 | + ) |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +pipeline { |
| 45 | + agent { |
| 46 | + label 'GPU-Monet' |
| 47 | + } |
| 48 | + options { |
| 49 | + timeout(time: 1, unit: 'HOURS') |
| 50 | + } |
| 51 | + environment { |
| 52 | + GIT_URL = "git@skymed.ai:AI-Platform/TensorGraph.git" |
| 53 | + } |
| 54 | + |
| 55 | + stages { |
| 56 | + stage('Clone & update repos') { |
| 57 | + steps { |
| 58 | + script{ |
| 59 | + stageName = 'Clone & update repos' |
| 60 | + try { |
| 61 | + // notifyBuild('STARTED',stageName) |
| 62 | + checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '${ghprbActualCommit}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '5744d880-cfb2-4925-b24a-8d5812f7dcad', name: 'tensorgraph', refspec: '+refs/pull/*/head:refs/remotes/origin/pr/*', url: 'git@skymed.ai:AI-Platform/TensorGraph.git']]] |
| 63 | + //git branch: 'develop', credentialsId: '5744d880-cfb2-4925-b24a-8d5812f7dcad', url: GIT_URL |
| 64 | + } catch (e) { |
| 65 | + currentBuild.result = "FAILED" |
| 66 | + notifyBuild(currentBuild.result, stageName) |
| 67 | + throw e |
| 68 | + } |
| 69 | + // finally { |
| 70 | + // notifyBuild(currentBuild.result, stageName) |
| 71 | + // } |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + stage('Parallel running'){ |
| 77 | + parallel { |
| 78 | + stage('SonarQube'){ |
| 79 | + stages{ |
| 80 | + stage('Static Code Analysis') { |
| 81 | + steps{ |
| 82 | + // requires SonarQube Scanner |
| 83 | + withSonarQubeEnv('sonar.skymed.ai') { |
| 84 | + sh ''' |
| 85 | + /opt/sonar-scanner/bin/sonar-scanner -X \ |
| 86 | + -Dsonar.projectKey=tensorgraph \ |
| 87 | + -Dsonar.sources=. \ |
| 88 | + -Dsonar.host.url=https://sonar.skymed.ai \ |
| 89 | + -Dsonar.login=b6252cd52eb8c205c39c3900a5364548b8c4502e |
| 90 | + ''' |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + stage('Code Quality Gate') { |
| 96 | + options { |
| 97 | + timeout(time: 1, unit: 'HOURS') |
| 98 | + } |
| 99 | + steps { |
| 100 | + script{ |
| 101 | + def qualitygate = waitForQualityGate() |
| 102 | + def failmsg = """ |
| 103 | + Pipeline aborted due to |
| 104 | + quality gate failure: |
| 105 | + ${qualitygate.status} |
| 106 | + Access to SonarQube dashboard |
| 107 | + (https://sonar.skymed.ai/dashboard?id=tensorgraph) |
| 108 | + to understand the warnings. |
| 109 | + """ |
| 110 | + if (qualitygate.status != "OK") { |
| 111 | + echo failmsg |
| 112 | + currentBuild.result = "FAILED" |
| 113 | + stageName = 'Code Quality Gate' |
| 114 | + notifyBuild(currentBuild.result, stageName) |
| 115 | + error "Pipeline aborted due to quality gate failure: ${qualitygate.status}" |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + stage('Workflow'){ |
| 124 | + stages{ |
| 125 | + |
| 126 | + stage('environment setup') { |
| 127 | + steps { |
| 128 | + script { |
| 129 | + stageName = 'environment setup' |
| 130 | + try { |
| 131 | + //sh 'apt-get update && apt-get install -y python-pip python3-pip' |
| 132 | + //sh 'pip install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy sklearn --user' |
| 133 | + //sh 'pip install --no-cache-dir tensorflow --user' |
| 134 | + //sh 'pip3 install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy sklearn --user' |
| 135 | + //sh 'pip3 install --no-cache-dir tensorflow --user' |
| 136 | + //sh "pip3 install -U pytest pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user" |
| 137 | + //sh "pip install -U pytest pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user" |
| 138 | + //sh 'python -m pytest --cov=tensorgraph test/' |
| 139 | + sh 'mkdir -p test-report' |
| 140 | + //sh 'python3 -m pytest --cov=tensorgraph --cov-report=xml:test-report/coverage.xml test/' |
| 141 | + } catch (e) { |
| 142 | + currentBuild.result = "FAILED" |
| 143 | + notifyBuild(currentBuild.result,stageName) |
| 144 | + throw e |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + stage('Run python3 pytest') { |
| 150 | + steps { |
| 151 | + script { |
| 152 | + stageName = 'Run python3 pytest' |
| 153 | + try { |
| 154 | + //sh 'apt-get update && apt-get install -y python-pip python3-pip' |
| 155 | + //sh 'pip install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy pytest sklearn --user' |
| 156 | + //sh 'pip install --no-cache-dir tensorflow --user' |
| 157 | + //sh 'pip3 install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy pytest sklearn --user' |
| 158 | + //sh 'pip3 install --no-cache-dir tensorflow --user' |
| 159 | + //sh "pip3 install -U pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user" |
| 160 | + //sh "pip install -U pytest pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user" |
| 161 | + //sh 'python -m pytest --cov=tensorgraph test/' |
| 162 | + //sh 'mkdir -p test-report' |
| 163 | + sh 'python3 -m pytest --cov=tensorgraph --cov-report=xml:test-report/coverage.xml test/' |
| 164 | + |
| 165 | + } catch (e) { |
| 166 | + currentBuild.result = "FAILED" |
| 167 | + notifyBuild(currentBuild.result,stageName) |
| 168 | + throw e |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | + stage('Run python2 pytest') { |
| 174 | + steps { |
| 175 | + script { |
| 176 | + stageName = 'Run python2 pytest' |
| 177 | + try { |
| 178 | + //sh 'apt-get update && apt-get install -y python-pip python3-pip' |
| 179 | + //sh 'pip install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy pytest sklearn --user' |
| 180 | + //sh 'pip install --no-cache-dir tensorflow --user' |
| 181 | + //sh 'pip3 install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy pytest sklearn --user' |
| 182 | + //sh 'pip3 install --no-cache-dir tensorflow --user' |
| 183 | + //sh "pip3 install -U pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user" |
| 184 | + //sh "pip install -U pytest pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user" |
| 185 | + sh 'python -m pytest test/' |
| 186 | + //sh 'mkdir -p test-report' |
| 187 | + //sh 'python3 -m pytest --cov=tensorgraph --cov-report=xml:test-report/coverage.xml test/' |
| 188 | + |
| 189 | + } catch (e) { |
| 190 | + currentBuild.result = "FAILED" |
| 191 | + notifyBuild(currentBuild.result,stageName) |
| 192 | + throw e |
| 193 | + } |
| 194 | + } |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | + } |
| 199 | + } |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + post { |
| 204 | + success { |
| 205 | + echo 'I succeeeded!' |
| 206 | + } |
| 207 | + failure { |
| 208 | + echo 'I failed :(' |
| 209 | + sendFailEmail() |
| 210 | + } |
| 211 | + unstable { |
| 212 | + echo 'I am unstable :/' |
| 213 | + } |
| 214 | + } |
| 215 | +} |
0 commit comments