forked from folio-org/mod-inventory-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
134 lines (113 loc) · 4.17 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
pipeline {
environment {
docker_repository = 'folioci'
docker_image = "${env.docker_repository}/mod-inventory-storage"
}
agent {
node {
label 'folio-jenkins-slave-docker'
}
}
stages {
stage('Prep') {
steps {
script {
currentBuild.displayName = "#${env.BUILD_NUMBER}-${env.JOB_BASE_NAME}"
}
slackSend "Build started: ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
step([$class: 'WsCleanup'])
}
}
stage('Checkout') {
steps {
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: false,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false]],
userRemoteConfigs: scm.userRemoteConfigs
])
echo " Checked out $env.BRANCH_NAME"
}
}
stage('Build') {
steps {
script {
def pom = readMavenPom file: 'pom.xml'
env.POM_VERSION = pom.version
}
echo "$env.POM_VERSION"
withMaven(jdk: 'OpenJDK 8 on Ubuntu Docker Slave Node',
maven: 'Maven on Ubuntu Docker Slave Node',
options: [junitPublisher(disabled: false,
ignoreAttachments: false),
artifactsPublisher(disabled: false)]) {
sh 'mvn clean integration-test'
}
}
}
stage('Build Docker') {
steps {
echo 'Building Docker image'
script {
docker.build("${env.docker_image}:${env.POM_VERSION}-${env.BUILD_NUMBER}", '--no-cache .')
// def dockerImage = docker.build("${env.docker_image}:${env.POM_VERSION}", '--no-cache .')
}
}
}
stage('Test') {
steps {
echo 'Some kind of additional integration testing should be done here before'
echo 'artifacts are deployed in subsequent stages.'
}
}
stage('Deploy to Docker Repo') {
when {
branch 'master'
}
steps {
echo "Pushing Docker image ${env.docker_image}:${env.POM_VERSION} to Docker Hub..."
script {
docker.withRegistry('https://index.docker.io/v1/', 'DockerHubIDJenkins') {
def dockerImage = docker.image("${env.docker_image}:${env.POM_VERSION}-${env.BUILD_NUMBER}")
// dockerImage.push()
// dockerImage.push('latest')
}
}
}
}
stage('Deploy to Maven Repo') {
when {
branch 'master'
}
steps {
withMaven(jdk: 'OpenJDK 8 on Ubuntu Docker Slave Node',
maven: 'Maven on Ubuntu Docker Slave Node',
options: [junitPublisher(disabled: false,
ignoreAttachments: false),
artifactsPublisher(disabled: false)]) {
echo 'Deploying java artifacts to Maven'
sh 'mvn -DskipTests=true -DdeployAtEnd=true deploy'
}
}
}
stage('Clean Up') {
steps {
sh "docker rmi ${docker_image}:${env.POM_VERSION}-${env.BUILD_NUMBER}"
sh "docker rmi ${docker_image}:latest"
}
}
}
post {
failure {
slackSend(color:'#FF0000', message: "Build failed: ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)")
}
success {
slackSend(color:'#008000', message: "Build successful: ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)")
}
}
}