-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsFile
52 lines (45 loc) · 1.26 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
node {
stage('Clean workspace') {
step([$class: 'WsCleanup'])
}
try{
def tagId = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
def api_image_name = "dpktan/andservice-read-api:" + tagId.replaceAll(/\//, "-")
def app
/* Checkout the code we are currently running against */
stage('Checkout') {
checkout scm
}
docker.image("gradle:3.5-jdk8-alpine").inside() {
if (env.BRANCH_NAME != 'uat' && env.BRANCH_NAME != 'master') {
stage('Run tests') {
sh 'gradle clean build -x test'
}
}
stage ('Build') {
sh 'gradle clean build -x test'
}
}
/* Build the Docker image with a Dockerfile */
stage ('Build Docker image') {
app = docker.build("${api_image_name}", '.')
}
/* Push the image to Docker Hub, using credentials we have setup separately on the worker node */
if (env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'uat' || env.BRANCH_NAME == 'master') {
stage('Push to Dockerhub') {
app.push()
app.push("${env.BRANCH_NAME}-latest")
}
}
}catch(error){
throw error
}finally {
try {
stage('Tidy Up') {
step([$class: 'WsCleanup'])
}
} catch (error) {
throw error
}
}
}