Jenkinsfile 1.81 KB
Newer Older
Lukas Wiest's avatar
Lukas Wiest committed
1
2
3

def version = ""

Dominik Vayhinger's avatar
Dominik Vayhinger committed
4
pipeline {
Lukas Wiest's avatar
Lukas Wiest committed
5

Dominik Vayhinger's avatar
Dominik Vayhinger committed
6
7
8
9
10
    environment {
        registry = "hftstuttgart/modocot-backend"
        registryCredential = 'Dockerhub'
        dockerImage = ''
    }
Lukas Wiest's avatar
Lukas Wiest committed
11

Dominik Vayhinger's avatar
Dominik Vayhinger committed
12
    agent any
Lukas Wiest's avatar
Lukas Wiest committed
13

Dominik Vayhinger's avatar
Dominik Vayhinger committed
14
15
16
17
    tools {
        jdk 'Java11'
        maven 'Maven_Home'
    }
Lukas Wiest's avatar
Lukas Wiest committed
18

Dominik Vayhinger's avatar
Dominik Vayhinger committed
19
    stages {
Lukas Wiest's avatar
Lukas Wiest committed
20
        stage('prepare') {
Dominik Vayhinger's avatar
Dominik Vayhinger committed
21
            steps {
Lukas Wiest's avatar
Lukas Wiest committed
22
23
24
25
26
27
28
29
30
31
32
                checkout ([
                    $class: 'GitSCM',
                    branches: scm.branches,
                    extensions: scm.extensions + [[$class: 'CloneOption', noTags: false, reference: '', shallow: false]],
                    userRemoteConfigs: scm.userRemoteConfigs
                ])
                script {
                    version = sh(script: 'git describe --tags --always', returnStdout: true).trim()
                    echo sh(script: 'env|sort', returnStdout: true)
                }

Dominik Vayhinger's avatar
Dominik Vayhinger committed
33
34
            }
        }
Lukas Wiest's avatar
Lukas Wiest committed
35
36

        stage('compile') {
Dominik Vayhinger's avatar
Dominik Vayhinger committed
37
            steps {
Lukas Wiest's avatar
Lukas Wiest committed
38
                sh 'mvn clean package'
Dominik Vayhinger's avatar
Dominik Vayhinger committed
39
40
            }
        }
Lukas Wiest's avatar
Lukas Wiest committed
41
42
43

        stage('build Docker image') {
            steps {
Dominik Vayhinger's avatar
Dominik Vayhinger committed
44
                script {
Lukas Wiest's avatar
Lukas Wiest committed
45
                    dockerImage = docker.build registry
Dominik Vayhinger's avatar
Dominik Vayhinger committed
46
47
48
                }
            }
        }
Lukas Wiest's avatar
Lukas Wiest committed
49
50
51
52
53
54

        stage('push development image') {
            steps {
                script {
                    docker.withRegistry( '', registryCredential ) {
                        dockerImage.push("${env.GIT_BRANCH}")
Dominik Vayhinger's avatar
Dominik Vayhinger committed
55
56
                    }
                }
Lukas Wiest's avatar
Lukas Wiest committed
57
58
            }
        }
Dominik Vayhinger's avatar
Dominik Vayhinger committed
59

Lukas Wiest's avatar
Lukas Wiest committed
60
61
62
63
        stage('release') {
            when {
                expression { version ==~ /[0-9]+.[0-9]+.[0-9]+/ }
            }
Dominik Vayhinger's avatar
Dominik Vayhinger committed
64
            steps {
Lukas Wiest's avatar
Lukas Wiest committed
65
66
67
68
69
70
                script {
                    docker.withRegistry( '', registryCredential ) {
                        dockerImage.push("latest")
                        dockerImage.push("${version}")
                    }
                }
Dominik Vayhinger's avatar
Dominik Vayhinger committed
71
72
73
74
            }
        }
    }
}