Skip to content

Commit

Permalink
fetch port number of the running container and port on the host
Browse files Browse the repository at this point in the history
  • Loading branch information
mramanathan committed Feb 20, 2018
1 parent 0b834c0 commit 77d8613
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions declarative-examples/simple-examples/dockercontainerPort.groovy
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()
}
}
}

0 comments on commit 77d8613

Please sign in to comment.