forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJenkinsfile
92 lines (74 loc) · 2.62 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!groovy
@Library('github.com/cloudogu/[email protected]')
import com.cloudogu.ces.cesbuildlib.*
node('docker') {
properties([
// Keep only the last 10 build to preserve space
buildDiscarder(logRotator(numToKeepStr: '10')),
// Don't run concurrent builds for a branch, because they use the same workspace directory
disableConcurrentBuilds(),
])
Docker docker = new Docker(this)
Git git = new Git(this)
catchError {
stage('Checkout') {
checkout scm
git.clean('')
// Otherwise git.isTag() will not be reliable. Jenkins seems to do a sparse checkout only
sh "git fetch --tags"
}
def devImage
def prodImage
String imageName = "cloudogu/reveal.js:${createVersion(git)}"
stage('Build Images') {
withEnv(['DOCKER_BUILDKIT=false']) {
devImage = docker.build "${imageName}-dev", '--build-arg ENV=dev .'
prodImage = docker.build imageName, '.'
}
}
stage('Test Images') {
smokeTest(devImage, '8000')
smokeTest(prodImage, '8080')
}
stage('Deploy Images') {
docker.withRegistry('', 'cesmarvin-dockerhub-access-token') {
if (git.isTag()) {
devImage.push()
prodImage.push()
}
if (env.BRANCH_NAME == "master") {
devImage.push('dev')
prodImage.push('latest')
}
}
}
}
mailIfStatusChanged(git.commitAuthorEmail)
}
String createVersion(git) {
String versionName
if (git.isTag()) {
versionName = git.tag
currentBuild.description = versionName
} else {
// E.g. "201708140933-1674930"
versionName = "${new Date().format('yyyyMMddHHmm')}-${git.commitHashShort}"
}
echo "Building version ${versionName} on branch ${env.BRANCH_NAME}"
return versionName
}
void smokeTest(def image, String port) {
String expectedTitle='myTitle'
Docker docker = new Docker(this)
image.withRun("-e TITLE=${expectedTitle}") { container ->
def ip = docker.findIp(container)
if (!ip || !getAndTestTitle("http://${ip}:${port}", expectedTitle)) {
echo "Container Smoke Test failed."
echo "Container log:"
echo new Sh(this).returnStdOut("docker logs ${container.id}")
}
}
}
void getAndTestTitle(String url, String title) {
sh ("wget -O- --retry-connrefused --tries=30 -q --wait=1 ${url} | grep ${title} ")
}