-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
111 lines (96 loc) · 3.84 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
pipeline {
agent any
stages {
stage('BeginProcess') {
steps {
parallel(
"BeginProcess": {
echo 'Building NucleoTest'
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Started the pipeline (<${env.BUILD_URL}|Open>)"
slackSend color: '#cecece', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Started the pipeline (<${env.BUILD_URL}|Open>)"
}
},
"Delete old build": {
sh 'rm -rf dockerbuild/'
}
)
}
}
stage('Build') {
steps {
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Compiling Spring application"
slackSend color: '#3e6be8', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Compiling Spring application"
}
sh 'chmod 0755 ./gradlew;./gradlew clean build --refresh-dependencies'
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Compiled Spring application"
slackSend color: '#42e565', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Compiled Spring application"
}
}
}
stage('Docker Build') {
steps {
parallel(
"Build Docker Image": {
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Building Docker image"
slackSend color: '#3e6be8', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Building Docker image"
}
sh '''mkdir dockerbuild/
cp build/libs/*.jar dockerbuild/app.jar
cp Dockerfile dockerbuild/Dockerfile
cd dockerbuild/
docker build -t nucleoteam/nucleotest:latest ./'''
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Built Docker image"
slackSend color: '#42e565', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Built Docker image"
}
},
"Save Artifact": {
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Archived artifacts"
slackSend color: '#f1f430', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Archived artifacts"
}
archiveArtifacts(artifacts: 'build/libs/*.jar', onlyIfSuccessful: true)
}
)
}
}
stage('Publish Latest Image') {
steps {
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Docker image publishing to DockerHub"
slackSend color: '#3e6be8', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Docker image publishing to DockerHub"
}
sh 'docker push nucleoteam/nucleotest:latest'
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Docker image published to DockerHub"
slackSend color: '#42e565', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Docker image published to DockerHub"
}
}
}
stage('Deploy') {
steps {
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Deploying docker image to Rancher"
slackSend color: '#3e6be8', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Deploying docker image to Rancher"
}
rancher(environmentId: '1a5', ports: '8000:8080', environments: '1i491', confirm: true, image: 'nucleoteam/nucleotest:latest', service: 'testapp/NucleoTest', endpoint: 'http://212.47.248.38:8080/v2-beta', credentialId: 'rancher-server')
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Deployed docker image to Rancher"
slackSend color: '#42e565', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Deployed docker image to Rancher"
}
}
}
stage('Finished') {
steps {
script {
echo "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Finished pipeline"
slackSend color: '#09a31e', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}] Finished pipeline"
}
}
}
}
}