forked from alecharp/simple-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
66 lines (53 loc) · 1.74 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
node {
stage 'Checkout'
checkout scm
sh 'git rev-parse HEAD > GIT_COMMIT'
short_commit = readFile('GIT_COMMIT').trim().take(7)
sh 'rm GIT_COMMIT'
def pom = readMavenPom file:'pom.xml'
currentBuild.description = "${pom.getVersion()} - ${short_commit}"
stage 'Build'
withMaven {
sh 'mvn clean verify'
}
step([$class: 'JUnitResultArchiver', testResults: 'target/surefire-reports/*.xml'])
step([$class: 'JUnitResultArchiver', testResults: 'target/failsafe-reports/*.xml'])
dir('target') {
archive "${pom.getArtifactId()}.${pom.getPackaging()}"
}
stash name: 'binary', includes: "target/${pom.getArtifactId()}.${pom.getPackaging()}"
dir('src/main/docker') {
stash name: 'dockerfile', includes: 'Dockerfile'
}
}
node('docker') {
unstash 'dockerfile'
unstash 'binary'
stage 'Building Docker Img'
image = docker.build("alecharp/simpleapp:${short_commit}")
container = image.run('-P')
sh "docker port ${container.id} 8080 > DOCKER_IP"
ip = readFile('DOCKER_IP').trim()
sh 'rm DOCKER_IP'
}
stage 'Container validation'
try {
input message: "http://${ip}. Is it ok?", ok: 'Publish it'
} finally {
node('docker') { container.stop() }
}
node('docker') {
stage 'Publishing Docker Img'
// requirement: local docker registry available on port 5000
docker.withRegistry('http://localhost:5000', '') {
image.push('latest')
}
}
// Custom step
def withMaven(def body) {
def javaHome = tool name: 'oracle-8u77', type: 'hudson.model.JDK'
def mavenHome = tool name: 'maven-3.3.9', type: 'hudson.tasks.Maven$MavenInstallation'
withEnv(["JAVA_HOME=${javaHome}", "PATH+MAVEN=${mavenHome}/bin"]) {
body.call()
}
}