-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
149 lines (137 loc) · 6.02 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env groovy
/* REQUIRED CREDENTTIALS
*
* - poterion-git [SSH Key] (global)
*/
def setup() {
if (env.VERSION) {
echo "Setup already done."
} else {
def major = sh(returnStdout: true, script: 'date +%Y').replaceAll(/\s/, "")
def minor
if (BRANCH_NAME == 'master' || BRANCH_NAME ==~ /release\/.*/) {
minor = sh(returnStdout: true, script: "git tag | grep -E '^v${major}\\.[0-9]+' | sort -r | head -n 1 | sed -E 's/^v${major}\\.([0-9]+)\$/\\1/'")
if (minor == "") minor = "0"
minor = minor.toInteger() + 1
} else if (BRANCH_NAME ==~ /\w+\/.*/) {
minor = BRANCH_NAME.replaceAll(/\w+\/(.*)/) { matches -> "${matches[1]}" }
} else {
minor = "DEV"
}
env.VERSION = major + '.' + minor
currentBuild.displayName = "${VERSION}.${BUILD_NUMBER}"
echo "Building version: ${VERSION}"
}
}
node {
//agent any
env.JAVA_HOME = "${tool name: 'JDK_8'}"
env.GRADLE = "${tool 'Gradle 5.2.1'}"
env.PATH = "${env.GRADLE}/bin:${env.PATH}"
properties([
//timeout(time: 1, unit: 'HOURS'),
disableConcurrentBuilds(),
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
])
timestamps {
ansiColor('xterm') {
stage('Checkout') {
if (BRANCH_NAME ==~ /release\/.*/) cleanWs()
checkout([
$class : 'GitSCM',
poll : true,
branches : [[name: "*/${BRANCH_NAME}"]],
doGenerateSubmoduleConfigurations: false,
extensions : [
[
$class : 'CloneOption',
depth : 1,
honorRefspec: true,
noTags : false,
reference : '',
shallow : false
],
[
$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false
],
[$class: 'PruneStaleBranch'],
[$class: 'WipeWorkspace']//,
//[$class: 'CleanBeforeCheckout']//,
//[$class: 'CleanCheckout']
],
submoduleCfg : [],
userRemoteConfigs : [
[
credentialsId: 'poterion-git',
url : 'ssh://[email protected]:22999/potpho/application.git'
]
]
])
sh 'git remote | grep github || git remote add github [email protected]:kubovy/footprint-photo-manager.git'
sh 'git tag -l | xargs git tag -d'
sshagent(credentials: ['poterion-git']) {
sh 'git fetch github'
sh 'git fetch github --tags'
}
setup()
milestone(10)
}
stage('Prepare OpenJDK') {
setup()
sh "gradle -Pversion=${VERSION} -Pjdks=/tmp/jdks extractOpenJDK"
milestone(20)
}
stage('Build') {
setup()
sh "gradle -Pversion=${VERSION} -Pjdks=/tmp/jdks extractOpenJDK build"
milestone(30)
}
stage('Build FatJar') {
setup()
sh "gradle -Pversion=${VERSION} -Pjdks=/tmp/jdks extractOpenJDK assembleFatJar"
archiveArtifacts([
fingerprint: true,
onlyIfSuccessful: true,
artifacts: "build/libs/footprint-all-${VERSION}.jar"
])
milestone(40)
}
stage('Build Self-Contained (Linux)') {
setup()
sh "gradle -Pversion=${VERSION} -Pjdks=/tmp/jdks extractOpenJDK assembleSelfContained"
archiveArtifacts([
fingerprint: true,
onlyIfSuccessful: true,
artifacts: "bundles/footprint-${VERSION}.tar.gz,"
+ "bundles/footprint-${VERSION}.deb,"
+ "bundles/footprint-${VERSION}.rpm"
])
milestone(50)
}
if (BRANCH_NAME == 'master') stage('Release') {
setup()
sshagent(credentials: ['poterion-git']) {
sh "git push github HEAD:${BRANCH_NAME} --force"
}
sh "rm -f dist/*.jar"
sh "mkdir -p dist"
sh "cp build/libs/footprint-all-${VERSION}.jar dist/footprint-all-${VERSION}.jar"
sh "git config user.name 'Jenkins'"
sh "git config user.email '[email protected]'"
sh "git add dist/*.jar"
sh "git commit -m \"Release ${VERSION}\""
sh "git tag -a -f v${VERSION} -m \"Release ${VERSION}\""
sh "git tag -a -f latest -m \"Release ${VERSION}\""
sshagent(credentials: ['poterion-git']) {
sh "git push github --tags --force"
}
milestone(90)
}
}
}
}