This repository has been archived by the owner on Jul 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
89 lines (86 loc) · 3.47 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
def gitCommitId = null
pipeline {
agent any
environment {
serviceName = "order"
namespace = "raksit"
replicaCount = 1
}
stages {
stage("Clone") {
steps {
script {
git branch: "master",
url: "git@github.com:raksit31667/example-spring-order.git",
credentialsId: "github"
gitCommitId = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
}
}
}
stage("Check style & pmd") {
steps {
sh "./gradlew checkStyleMain -i"
sh "./gradlew pmdMain -i"
}
}
stage("Unit test") {
steps {
sh "./gradlew test -i"
}
}
stage("Isolation test") {
steps {
sh "./gradlew isolationTest -i"
}
}
stage("Sonar Check") {
steps {
sh "./gradlew sonarqube -Dsonar.host.url=https://sonarqube-raksit31667.1d35.starter-us-east-1.openshiftapps.com -Dsonar.projectVersion=${gitCommitId}"
}
}
stage("Build") {
steps {
sh "./gradlew build -i"
sh "tar cvf ${serviceName}.tar Dockefile api-service/build/libs/api-service-0.0.1.jar"
stash name: "package", includes: "${serviceName}.tar"
}
}
stage("Build Image and push it to ImageStream") {
steps {
unstash name: "package"
sh "oc process -f ${serviceName}-build-and-imagestream.yaml -p JENKINS_BUILD_NUMBER=${env.BUILD_NUMBER} -p GIT_HASH=${gitCommitId} | oc apply --namespace='${namespace}' -f -"
sh "oc start-build ${serviceName} --from-archive=${serviceName}.tar --follow --namespace='${namespace}'"
}
}
stage("Tag Image") {
steps {
sh "oc tag ${namespace}/${serviceName}:latest ${namespace}/${serviceName}:${gitCommitId} --namespace='${namespace}'"
}
}
stage("Deploy") {
steps {
script {
def dockerRegistryAndImageName = sh(
script: "oc get imagestream --namespace='${namespace}' ${serviceName} -o='jsonpath={.status.dockerImageRepository}'",
returnStdout: true).trim()
sh "oc process openshift/${serviceName}-deployment-config.yaml --ignore-unknown-parameters=true -p REPLICAS='${replicaCount}' DOCKER_REGISTRY='${dockerRegistryAndImageName}:${gitCommitId}' -p SPRING_PROFILES_ACTIVE='dev' | oc apply --namespace='${namespaceDev}' -f -"
openshiftDeploy depCfg: "${serviceName}-deployment", namespace: "${namespace}"
sh "oc rollout status dc ${serviceName}-deployment -w --namespace='${namespace}'"
sh "oc apply openshift/${serviceName}-service.yaml --namespace='${namespace}' -f -"
}
}
}
stage('Verify Deployment') {
steps {
script {
try {
verifyDeployment(namespace, serviceName, replicaCount)
} catch (Throwable e) {
sh "oc rollback ${serviceName} --namespace='${namespace}'"
throw e
}
}
}
}
}
}