-
Notifications
You must be signed in to change notification settings - Fork 79
/
Jenkinsfile
132 lines (118 loc) · 3.55 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!groovy
properties([[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '10']]])
stage('build') {
node {
checkout scm
def v = version()
currentBuild.displayName = "${env.BRANCH_NAME}-${v}-${env.BUILD_NUMBER}"
mvn "clean verify"
}
}
stage('build docker image') {
node {
mvn "clean package docker:build -DskipTests"
}
}
def branch_type = get_branch_type "${env.BRANCH_NAME}"
def branch_deployment_environment = get_branch_deployment_environment branch_type
if (branch_deployment_environment) {
stage('deploy') {
if (branch_deployment_environment == "prod") {
timeout(time: 1, unit: 'DAYS') {
input "Deploy to ${branch_deployment_environment} ?"
}
}
node {
sh "echo Deploying to ${branch_deployment_environment}"
//TODO specify the deployment
}
}
if (branch_deployment_environment != "prod") {
stage('integration tests') {
node {
sh "echo Running integration tests in ${branch_deployment_environment}"
//TODO do the actual tests
}
}
}
}
if (branch_type == "dev") {
stage('start release') {
timeout(time: 1, unit: 'HOURS') {
input "Do you want to start a release?"
}
node {
sshagent(['f1ad0f5d-df0d-441a-bea0-fd2c34801427']) {
mvn("jgitflow:release-start")
}
}
}
}
if (branch_type == "release") {
stage('finish release') {
timeout(time: 1, unit: 'HOURS') {
input "Is the release finished?"
}
node {
sshagent(['f1ad0f5d-df0d-441a-bea0-fd2c34801427']) {
mvn("jgitflow:release-finish -Dmaven.javadoc.skip=true -DnoDeploy=true")
}
}
}
}
if (branch_type == "hotfix") {
stage('finish hotfix') {
timeout(time: 1, unit: 'HOURS') {
input "Is the hotfix finished?"
}
node {
sshagent(['f1ad0f5d-df0d-441a-bea0-fd2c34801427']) {
mvn("jgitflow:hotfix-finish -Dmaven.javadoc.skip=true -DnoDeploy=true")
}
}
}
}
// Utility functions
def get_branch_type(String branch_name) {
//Must be specified according to <flowInitContext> configuration of jgitflow-maven-plugin in pom.xml
def dev_pattern = ".*development"
def release_pattern = ".*release/.*"
def feature_pattern = ".*feature/.*"
def hotfix_pattern = ".*hotfix/.*"
def master_pattern = ".*master"
if (branch_name =~ dev_pattern) {
return "dev"
} else if (branch_name =~ release_pattern) {
return "release"
} else if (branch_name =~ master_pattern) {
return "master"
} else if (branch_name =~ feature_pattern) {
return "feature"
} else if (branch_name =~ hotfix_pattern) {
return "hotfix"
} else {
return null;
}
}
def get_branch_deployment_environment(String branch_type) {
if (branch_type == "dev") {
return "dev"
} else if (branch_type == "release") {
return "staging"
} else if (branch_type == "master") {
return "prod"
} else {
return null;
}
}
def mvn(String goals) {
def mvnHome = tool "Maven-3.2.3"
def javaHome = tool "JDK1.8.0_102"
withEnv(["JAVA_HOME=${javaHome}", "PATH+MAVEN=${mvnHome}/bin"]) {
sh "mvn -B ${goals}"
}
}
def version() {
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
return matcher ? matcher[0][1] : null
}