-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch port number of the running container and port on the host
- Loading branch information
1 parent
0b834c0
commit 77d8613
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
declarative-examples/simple-examples/dockercontainerPort.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
pipeline { | ||
agent any | ||
|
||
options { | ||
timestamps() | ||
} | ||
|
||
environment { | ||
IMAGE = "custom-tutum" | ||
} | ||
|
||
stages { | ||
stage('prep') { | ||
steps { | ||
script { | ||
env.GIT_HASH = sh( | ||
script: "git show --oneline | head -1 | cut -d' ' -f1", | ||
returnStdout: true | ||
).trim() | ||
} | ||
} | ||
} | ||
stage('build') { | ||
steps { | ||
script { | ||
image = docker.build("${IMAGE}") | ||
println "Newly generated image, " + image.id | ||
} | ||
} | ||
} | ||
stage('test') { | ||
steps { | ||
script { | ||
// https://hub.docker.com/r/tutum/hello-world/ | ||
def container = image.run('-p 80') | ||
def contport = container.port(80) | ||
def resp = sh(returnStdout: true, | ||
script: """ | ||
set -x | ||
curl -w "%{http_code}" -o /dev/null -s \ | ||
http://\"${contport}\" | ||
""" | ||
).trim() | ||
if ( resp == "200" ) { | ||
println "tutum hello world is alive and kicking!" | ||
currentBuild.result = "SUCCESS" | ||
} else { | ||
println "Humans are mortals." | ||
currentBuild.result = "FAILURE" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
post { | ||
always { | ||
cleanWs() | ||
} | ||
} | ||
} |