forked from beedemo/mobile-deposit-api
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Jenkinsfile
97 lines (89 loc) · 3.92 KB
/
Jenkinsfile
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
def buildVersion = null
properties([[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5']]])
stage 'Build'
if(!env.JOB_NAME.startsWith("team-productivity/beedemo-sa/mobile-deposit-api/")) {
echo 'only build for beedemo-sa org folder'
error 'invalid project path'
}
node('docker-cloud') {
checkout scm
docker.image('kmadel/maven:3.3.3-jdk-8').inside('-v /data:/data') {
sh 'mvn -Dmaven.repo.local=/data/mvn/repo clean package'
}
stash name: 'pom', includes: 'pom.xml, src, target'
}
if(!env.BRANCH_NAME.startsWith("PR")){
checkpoint 'Build Complete'
stage 'Quality Analysis'
node('docker-cloud') {
try {
unstash 'pom'
//test in paralell
parallel(
integrationTests: {
docker.image('kmadel/maven:3.3.3-jdk-8').inside('-v /data:/data') {
sh 'mvn -Dmaven.repo.local=/data/mvn/repo verify'
}
}, sonarAnalysis: {
withCredentials([[$class: 'StringBinding', credentialsId: 'sonar.beedemo', variable: 'TOKEN']]) {
echo 'running sonar tests'
docker.image('kmadel/maven:3.3.3-jdk-8').inside('-v /data:/data') {
sh 'mvn -Dmaven.repo.local=/data/mvn/repo -Dsonar.scm.disabled=True -Dsonar.login=$TOKEN sonar:sonar'
}
echo 'finished sonar tests'
}
}, failFast: true
)
} catch (x) {
currentBuild.result = "failed"
hipchatSend color: 'RED', message: "${env.JOB_NAME} ${env.BUILD_NUMBER} status: ${currentBuild.result} <a href=\'${env.BUILD_URL}\'>Open</a>", room: '1613593', server: 'cloudbees.hipchat.com', token: 'A6YX8LxNc4wuNiWUn6qHacfO1bBSGXQ6E1lELi1z', v2enabled: true
throw x
}
}
}
if(env.BRANCH_NAME=="master"){
checkpoint 'Quality Analysis Complete'
stage name: 'Version Release', concurrency: 1
node('docker-cloud') {
unstash 'pom'
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
if (matcher) {
buildVersion = matcher[0][1]
echo "Release version: ${buildVersion}"
}
matcher = null
docker.withServer('tcp://52.27.249.236:3376', 'beedemo-swarm-cert'){
stage 'Build Docker Image'
def mobileDepositApiImage
dir('target') {
mobileDepositApiImage = docker.build "kmadel/mobile-deposit-api:${buildVersion}"
}
stage 'Deploy to Prod'
try{
sh "docker stop beedemo-swarm-master/mobile-deposit-api"
sh "docker rm beedemo-swarm-master/mobile-deposit-api"
} catch (Exception _) {
echo "no container to stop"
}
//docker traceability rest call
container = mobileDepositApiImage.run("--name mobile-deposit-api -p 8080:8080 --env='constraint:node==beedemo-swarm-master'")
sh "curl http://webhook:[email protected]/api-team/docker-traceability/submitContainerStatus \
--data-urlencode status=deployed \
--data-urlencode hostName=prod-server-1 \
--data-urlencode hostName=prod \
--data-urlencode imageName=cloudbees/mobile-deposit-api \
--data-urlencode inspectData=\"\$(docker inspect $container.id)\""
stage 'Publish Docker Image'
sh "docker -v"
//use withDockerRegistry to make sure we are logged in to docker hub registry
withDockerRegistry(registry: [credentialsId: 'docker-registry-kmadel-login']) {
mobileDepositApiImage.push()
}
}
}
}
node('docker-cloud') {
//update hipchat with success
currentBuild.result = "success"
hipchatSend color: 'GREEN', message: "${env.JOB_NAME} ${env.BUILD_NUMBER} status: ${currentBuild.result} <a href=\'${env.BUILD_URL}\'>Open</a>", room: '1613593', server: 'cloudbees.hipchat.com', token: 'A6YX8LxNc4wuNiWUn6qHacfO1bBSGXQ6E1lELi1z', v2enabled: true
}