forked from cloudogu/hello-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
51 lines (41 loc) · 1.41 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
#!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 image
String imageName = "cloudogu/hello-k8s:${readVersion()}"
stage('Build Images') {
image = docker.build imageName, '.'
}
stage('Deploy Images') {
docker.withRegistry('', 'cesmarvin-dockerhub-access-token') {
//if (git.isTag()) {
if (env.BRANCH_NAME == "master") {
image.push()
image.push('latest')
}
}
}
}
mailIfStatusChanged(git.commitAuthorEmail)
}
String readVersion() {
return sh (script: 'grep version app/package.json | sed \'s/"version": "\\(.*\\)".*/\\1/\'',
returnStdout: true,
label: 'readVersion').trim()
}