Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch port number of the running container and port on the host #87

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions declarative-examples/simple-examples/dockercontainerPort.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pipeline {
environment {
IMAGE = "docker-repository/custom-tutum"
}

// build agent where docker commands can be run
agent 'docker-node'

stages {
stage('build') {
steps {
script {
// Dockerfile should be stored at the dir level same as that of Jenkinsfile
// Contents of Dockerfile,
/*
FROM tutum/hello-world
EXPOSE 80
*/
image = docker.build("${IMAGE}")
println "Newly generated image, " + image.id
}
}
}
stage('test') {
steps {
script {
// https://hub.docker.com/r/tutum/hello-world/
// build agent should have 'curl' installed.
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 app is alive and kicking!"
currentBuild.result = "SUCCESS"
} else {
println "tutum hello world app isn't reachable!!!"
currentBuild.result = "FAILURE"
}
}
}
}
}
}