-
Notifications
You must be signed in to change notification settings - Fork 7
/
dp.groovy
104 lines (90 loc) · 2.33 KB
/
dp.groovy
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
def version = "${env.BUILD_NUMBER}"
def server = Artifactory.server 'artifactory'
def rtGradle = Artifactory.newGradleBuild()
pipeline {
environment {
gradleVersion = "--offline -Pversion=${env.BUILD_NUMBER}"
}
agent {
label 'docker'
}
stages {
stage('Checkout') {
steps {
git changelog: false, poll: false, url: 'https://github.com/aatarasoff/spring-boot-example-for-jenkins-pipeline'
}
}
stage('Build jar') {
steps {
script {
rtGradle.useWrapper = true
rtGradle.deployer server: server, repo: 'maven'
rtGradle.run switches: env.gradleVersion, tasks: 'build'
}
}
}
stage('QA') {
when {
expression {
withSonarQubeEnv('sonar') {
sh './gradlew ' + env.gradleVersion + ' --info sonarqube'
}
sleep 5
return waitForQualityGate().status != 'OK'
}
}
steps {
error "Pipeline aborted due to quality gate failure"
}
}
stage('Publish jar') {
steps {
script {
def buildInfo = rtGradle.run switches: env.gradleVersion, tasks: 'build artifactoryPublish'
}
}
}
stage('Publish Docker') {
steps {
sh "curl -o app.jar http://artifactory:8081/artifactory/maven/demo/${version}/demo-${version}.jar"
script {
docker.withServer('tcp://socatdockersock:2375') {
docker.withRegistry('http://docker.artifactory:8000') {
docker.build("demo").push("${version}")
}
}
}
}
}
stage('Deploy') {
steps {
script {
docker.withServer('tcp://socatdockersock:2375') {
sh """docker run --net jenkinspipelinelivedemo_default \
--name demo${version} -d -p 10080 docker.artifactory:8000/demo:${version}"""
}
}
}
}
stage('Post-deploy') {
steps {
timeout(20) {
retry(3) {
sleep 5
sh "curl http://demo${version}:10080/health"
}
}
}
}
}
post {
always {
script {
docker.withServer('tcp://socatdockersock:2375') {
sh "docker rm -f demo${version}"
sh "docker rmi -f docker.artifactory:8000/demo:${version}"
}
}
}
}
}