-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
110 lines (109 loc) · 2.41 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
#!/usr/bin/env groovy
@Library('deployment-api') _
pipeline {
agent none
environment {
DEPLOYMENT_API_APP_NAME = 'CoolService'
DEPLOYMENT_API_SERVICE_URL = 'http://deployment-api-service.marathon.l4lb.thisdcos.directory:8080'
DOCKER_REGISTRY = 'registry.marathon.l4lb.thisdcos.directory:5000'
DOCKER_IMAGE = 'micahnoland/cool-service'
}
options {
timeout(time: 1, unit: 'HOURS')
}
stages {
stage('Setup') {
agent any
steps {
script {
checkout scm
}
stash name: 'work', useDefaultExcludes: false
}
}
stage('Maven Test') {
agent any
steps {
deleteDir()
unstash 'work'
script {
try {
sh('./mvnw clean test')
} catch (e) {
currentBuild.result = 'FAILURE'
throw e
} finally {
junit "**/target/surefire-reports/*.xml"
}
}
stash name: 'work', useDefaultExcludes: false
}
}
stage('Maven Install') {
agent any
steps {
deleteDir()
unstash 'work'
sh './mvnw clean install -DskipTests'
stash name: 'work', useDefaultExcludes: false
}
}
stage('Docker') {
agent any
steps {
deleteDir()
unstash 'work'
script {
docker.withRegistry("http://${env.DOCKER_REGISTRY}") {
docker.build("${env.DOCKER_IMAGE}:${env.BUILD_ID}").push()
}
}
stash name: 'work', useDefaultExcludes: false
}
}
stage('Dev Deployment') {
agent any
steps {
script {
deploymentApi(env.DEPLOYMENT_API_APP_NAME, 'dev', "${env.DOCKER_REGISTRY}/${env.DOCKER_IMAGE}:${env.BUILD_ID}", env.DEPLOYMENT_API_SERVICE_URL)
}
}
}
stage('Deploy to Prod?') {
agent none
when {
expression {
boolean deploy = false
try {
// Should have a timeout here if one is not defined in the pipeline { options } section
input message: 'Deploy to Production?'
deploy = true
} catch (final ignore) {
deploy = false
}
return deploy
}
}
steps {
script {
env.DEPLOY_TO_PROD = 'true'
}
}
}
stage('Prod Deployment') {
agent any
when {
expression {
if (env.DEPLOY_TO_PROD == 'true') {
return true
}
}
}
steps {
script {
deploymentApi(env.DEPLOYMENT_API_APP_NAME, 'prod', "${env.DOCKER_REGISTRY}/${env.DOCKER_IMAGE}:${env.BUILD_ID}", env.DEPLOYMENT_API_SERVICE_URL)
}
}
}
}
}