Skip to content

Commit 77d8613

Browse files
committed
fetch port number of the running container and port on the host
1 parent 0b834c0 commit 77d8613

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
pipeline {
2+
agent any
3+
4+
options {
5+
timestamps()
6+
}
7+
8+
environment {
9+
IMAGE = "custom-tutum"
10+
}
11+
12+
stages {
13+
stage('prep') {
14+
steps {
15+
script {
16+
env.GIT_HASH = sh(
17+
script: "git show --oneline | head -1 | cut -d' ' -f1",
18+
returnStdout: true
19+
).trim()
20+
}
21+
}
22+
}
23+
stage('build') {
24+
steps {
25+
script {
26+
image = docker.build("${IMAGE}")
27+
println "Newly generated image, " + image.id
28+
}
29+
}
30+
}
31+
stage('test') {
32+
steps {
33+
script {
34+
// https://hub.docker.com/r/tutum/hello-world/
35+
def container = image.run('-p 80')
36+
def contport = container.port(80)
37+
def resp = sh(returnStdout: true,
38+
script: """
39+
set -x
40+
curl -w "%{http_code}" -o /dev/null -s \
41+
http://\"${contport}\"
42+
"""
43+
).trim()
44+
if ( resp == "200" ) {
45+
println "tutum hello world is alive and kicking!"
46+
currentBuild.result = "SUCCESS"
47+
} else {
48+
println "Humans are mortals."
49+
currentBuild.result = "FAILURE"
50+
}
51+
}
52+
}
53+
}
54+
}
55+
post {
56+
always {
57+
cleanWs()
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)