github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/build/Jenkinsfile.pr (about) 1 #!/usr/bin/env groovy 2 3 @Library('shared-pipelines') _ 4 import org.xenia.Utils 5 import java.util.*; 6 def utils = new org.xenia.Utils() 7 def rnd = UUID.randomUUID().toString() 8 9 pipeline { 10 agent { 11 label 'default-mm-builder' 12 } 13 14 options { 15 buildDiscarder(logRotator(numToKeepStr: '3')) 16 timeout(time: 1, unit: 'HOURS') 17 } 18 19 environment { 20 COMPOSE_PROJECT_NAME="${rnd}-${env.BUILD_NUMBER}" 21 } 22 23 stages { 24 stage('Setup') { 25 steps { 26 script { 27 utils.stopOldBuilds() 28 } 29 cleanWs notFailBuild: true 30 sh """ 31 mkdir -p src/github.com/xzl8028/xenia-server 32 mkdir -p src/github.com/xzl8028/xenia-webapp 33 mkdir -p src/github.com/xzl8028/enterprise 34 """ 35 dir('src/github.com/xzl8028/xenia-server') { 36 checkout scm 37 } 38 dir('src/github.com/xzl8028/xenia-webapp') { 39 checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '310159d3-f7c5-4f5d-bfa1-151e3ef2db57', url: 'https://github.com/xzl8028/xenia-webapp.git']]] 40 } 41 dir('src/github.com/xzl8028/enterprise') { 42 checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '310159d3-f7c5-4f5d-bfa1-151e3ef2db57', url: 'https://github.com/xzl8028/enterprise.git']]] 43 } 44 dir('src/github.com/xzl8028/enterprise') { 45 ansiColor('xterm') { 46 sh """ 47 #!/bin/bash -ex 48 git checkout $env.BRANCH_NAME || git checkout $env.CHANGE_BRANCH || git checkout $env.GIT_BRANCH || git checkout $env.CHANGE_TARGET || git checkout master || echo 1 49 export EE_GIT_COMMIT=\$(git rev-parse HEAD) 50 51 echo EE Commit: \${EE_GIT_COMMIT} 52 """ 53 } 54 } 55 dir('src/github.com/xzl8028/xenia-webapp') { 56 withDockerContainer(args: '', image: 'xenia/xenia-build-webapp:oct-2-2018') { 57 ansiColor('xterm') { 58 sh """ 59 #!/bin/bash -ex 60 git checkout $env.BRANCH_NAME || git checkout $env.CHANGE_BRANCH || git checkout $env.GIT_BRANCH || git checkout $env.CHANGE_TARGET || git checkout master 61 rm -rf ./dist 62 export WEBAPP_GIT_COMMIT=\$(git rev-parse HEAD) 63 64 echo Webapp Commit: \${WEBAPP_GIT_COMMIT} 65 66 curl -f -o ./dist.tar.gz https://releases.xenia.com/xenia-webapp/commit/\${WEBAPP_GIT_COMMIT}/xenia-webapp.tar.gz && mkdir ./dist && tar -xvf ./dist.tar.gz -C ./dist --strip-components=1 || make node_modules test build 67 """ 68 } 69 } 70 } 71 } 72 } 73 74 stage('Check i18n') { 75 environment { 76 GOPATH = "/go" 77 } 78 79 steps { 80 withDockerContainer(args: '-u root --privileged -v ${WORKSPACE}/src:/go/src/', image: 'xenia/xenia-build-server:feb-28-2019') { 81 ansiColor('xterm') { 82 sh """ 83 cd /go/src/github.com/xzl8028/xenia-server 84 cp i18n/en.json /tmp/en.json 85 make i18n-extract 86 diff /tmp/en.json i18n/en.json 87 """ 88 } 89 } 90 } 91 } 92 93 stage('Build') { 94 environment { 95 GOPATH = "/go" 96 } 97 98 steps { 99 withDockerContainer(args: '-u root --privileged -v ${WORKSPACE}/src:/go/src/', image: 'xenia/xenia-build-server:feb-28-2019') { 100 ansiColor('xterm') { 101 sh """ 102 cd /go/src/github.com/xzl8028/xenia-server 103 make config-reset 104 make check-style BUILD_NUMBER='${BRANCH_NAME}-${BUILD_NUMBER}' 105 make build BUILD_NUMBER='${BRANCH_NAME}-${BUILD_NUMBER}' 106 make package BUILD_NUMBER='${BRANCH_NAME}-${BUILD_NUMBER}' 107 """ 108 } 109 } 110 } 111 } 112 113 stage('Test') { 114 environment { 115 GOPATH = "/go" 116 TEST_DATABASE_MYSQL_DSN = "mmuser:mostest@tcp(mysql:3306)/xenia_test?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s" 117 TEST_DATABASE_POSTGRESQL_DSN = "postgres://mmuser:mostest@postgres:5432/xenia_test?sslmode=disable&connect_timeout=10" 118 TEST_DATABASE_MYSQL_ROOT_PASSWD = "mostest" 119 CI_INBUCKET_HOST = "inbucket" 120 CI_MINIO_HOST = "minio" 121 CI_INBUCKET_PORT = "10080" 122 CI_MINIO_PORT = "9000" 123 CI_INBUCKET_SMTP_PORT = "10025" 124 CI_LDAP_HOST = "openldap" 125 IS_CI = true 126 MM_SQLSETTINGS_DATASOURCE = "mmuser:mostest@tcp(mysql:3306)/xenia_test?charset=utf8mb4,utf8" 127 MM_EMAILSETTINGS_SMTPSERVER = "inbucket" 128 MM_EMAILSETTINGS_SMTPPORT = "10025" 129 MM_ELASTICSEARCHSETTINGS_CONNECTIONURL = "http://elasticsearch:9200" 130 LDAP_DATA = "test" 131 } 132 133 steps { 134 dir('src/github.com/xzl8028/xenia-server/build') { 135 ansiColor('xterm') { 136 sh """ 137 docker-compose --no-ansi run --rm start_dependencies 138 docker-compose --no-ansi ps 139 docker-compose --no-ansi exec -T openldap bash -c 'ldapadd -x -D "cn=admin,dc=mm,dc=test,dc=com" -w mostest -f /${LDAP_DATA}-data.ldif'; 140 """ 141 } 142 } 143 144 withDockerContainer(args: "-u root --privileged --net ${COMPOSE_PROJECT_NAME}_mm-test -v ${WORKSPACE}/src:/go/src/", image: 'xenia/xenia-build-server:feb-28-2019') { 145 ansiColor('xterm') { 146 sh """ 147 cd /go/src/github.com/xzl8028/xenia-server 148 149 mkdir -p client/plugins 150 cat config/config.json 151 152 make test-server BUILD_NUMBER='${BRANCH_NAME}-${BUILD_NUMBER}' TESTFLAGS= TESTFLAGSEE= 153 154 """ 155 } 156 withCredentials([string(credentialsId: 'CODECOV_TOKEN', variable: 'CODECOV')]) { 157 sh ''' 158 cd /go/src/github.com/xzl8028/xenia-server 159 curl -s https://codecov.io/bash | bash -s - -t $CODECOV || echo 'Codecov failed to upload' 160 ''' 161 } 162 } 163 } 164 } 165 166 stage('Push to S3') { 167 stages { 168 stage('Pull request') { 169 when { 170 allOf { 171 expression { env.CHANGE_ID != null } 172 expression { env.CHANGE_TARGET != null } 173 } 174 } 175 steps { 176 dir('src/github.com/xzl8028/xenia-server/dist') { 177 step([$class: 'S3BucketPublisher', dontWaitForConcurrentBuildCompletion: false, entries: [[ 178 bucket: "releases.xenia.com/xenia-platform-pr/${CHANGE_ID}", 179 excludedFile: '', 180 flatten: true, 181 gzipFiles: false, 182 keepForever: false, 183 managedArtifacts: false, 184 noUploadOnFailure: true, 185 selectedRegion: 'us-east-1', 186 showDirectlyInBrowser: false, 187 sourceFile: '*.tar.gz', 188 storageClass: 'STANDARD', 189 uploadFromSlave: false, 190 useServerSideEncryption: false, 191 userMetadata: [[key: 'Cache-Control', value: 'no-cache']] 192 ], [ 193 bucket: "releases.xenia.com/xenia-platform-pr/${CHANGE_BRANCH}", 194 excludedFile: '', 195 flatten: true, 196 gzipFiles: false, 197 keepForever: false, 198 managedArtifacts: false, 199 noUploadOnFailure: true, 200 selectedRegion: 'us-east-1', 201 showDirectlyInBrowser: false, 202 sourceFile: '*.tar.gz', 203 storageClass: 'STANDARD', 204 uploadFromSlave: false, 205 useServerSideEncryption: false, 206 userMetadata: [[key: 'Cache-Control', value: 'no-cache']] 207 ]], profileName: 'Releases', userMetadAta: []]) 208 } 209 } 210 } 211 stage('Branch') { 212 when { 213 expression { env.CHANGE_ID == null } 214 } 215 steps { 216 dir('src/github.com/xzl8028/xenia-server/dist') { 217 step([$class: 'S3BucketPublisher', dontWaitForConcurrentBuildCompletion: false, entries: [[ 218 bucket: "releases.xenia.com/xenia-platform-pr/${BRANCH_NAME}", 219 excludedFile: '', 220 flatten: true, 221 gzipFiles: false, 222 keepForever: false, 223 managedArtifacts: false, 224 noUploadOnFailure: true, 225 selectedRegion: 'us-east-1', 226 showDirectlyInBrowser: false, 227 sourceFile: '*.tar.gz', 228 storageClass: 'STANDARD', 229 uploadFromSlave: false, 230 useServerSideEncryption: false, 231 userMetadata: [[key: 'Cache-Control', value: 'no-cache']] 232 ]], profileName: 'Releases', userMetadAta: []]) 233 } 234 } 235 } 236 } 237 } 238 239 stage('Clean checkout') { 240 when { 241 expression { env.CHANGE_ID != null } 242 } 243 // We need to perform a clean checkout here to ge the original git commit hash from the PR 244 // Jenkins now merges master in top of the PR and this generate a new git hash 245 // We need to do that to build the docker image based on the original git commit and then this will be used by 246 // mattermod to update the test server. 247 steps { 248 sh """ 249 mkdir -p /tmp/xenia-server 250 """ 251 dir('/tmp/xenia-server') { 252 checkout([$class: 'GitSCM', branches: [[name: 'FETCH_HEAD']], 253 doGenerateSubmoduleConfigurations: false, extensions: [], 254 submoduleCfg: [], userRemoteConfigs: [ 255 [refspec: "+refs/pull/${CHANGE_ID}/head:refs/remotes/origin/PR-${CHANGE_ID}", 256 credentialsId: "310159d3-f7c5-4f5d-bfa1-151e3ef2db57",url: "https://github.com/xzl8028/xenia-server.git"]]]) 257 sh 'git rev-parse --short HEAD' 258 } 259 } 260 } 261 262 stage('Trigger docker image') { 263 environment { 264 GIT_COMMIT_SHORT = sh( 265 script: "cd /tmp/xenia-server && printf \$(git rev-parse --short HEAD)", 266 returnStdout: true 267 ) 268 } 269 when { 270 expression { env.CHANGE_ID != null } 271 } 272 steps { 273 build job: '../../mk/xenia-enterprise-edition-release', parameters: [string(name: 'RELEASE', value: "${CHANGE_ID}"), booleanParam(name: 'FROM_PR', value: true),string(name: 'PR_TAG', value: "${GIT_COMMIT_SHORT}")], propagate: false, wait: false 274 } 275 } 276 } 277 278 post { 279 always { 280 dir('src/github.com/xzl8028/xenia-server') { 281 junit allowEmptyResults: true, healthScaleFactor: 0.0, testResults: 'report*.xml' 282 archiveArtifacts 'report*.xml' 283 } 284 dir('src/github.com/xzl8028/xenia-server/build') { 285 ansiColor('xterm') { 286 sh """ 287 docker-compose --no-ansi down -v 288 """ 289 } 290 } 291 } 292 cleanup { 293 cleanWs notFailBuild: true 294 } 295 } 296 }