Skip to content
Open
Changes from 1 commit
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
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(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this GIT_HASH environment variable required by the script? I cannot see where it is dereferenced.

script: "git show --oneline | head -1 | cut -d' ' -f1",
Copy link

@goostleek goostleek Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the latest commit hash by a pure git command: git rev-parse HEAD. The result will be the same.

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()
}
}
}