-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
108 lines (86 loc) · 3.75 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
def performRelease = false
def gradleOpts = "-s --build-cache -PlocalNexus=http://nexus3:8081/repository/public"
def buildCacheDir = ""
pipeline {
agent { label "gradle-8.10-jdk11" }
parameters {
string(defaultValue: '', description: 'Extra Gradle Options', name: 'extraGradleOpts')
booleanParam(name: 'majorRelease', defaultValue: false, description: 'Perform a major release')
booleanParam(name: 'minorRelease', defaultValue: false, description: 'Perform a minor release')
booleanParam(name: 'patchRelease', defaultValue: false, description: 'Perform a patch release')
booleanParam(name: 'publish', defaultValue: false, description: 'Publish to nexus')
string(name: 'baseBuildCacheDir', defaultValue: '/cache', description: 'Base build cache dir')
string(name: 'buildCacheName', defaultValue: 'default', description: 'Build cache name')
}
stages {
stage('Prepare') {
steps {
script {
sh "wget http://nexus3:8081/repository/public/com/fincher/gradle-cache/0.0.1/gradle-cache-0.0.1.tgz -O /tmp/gradle-cache.tgz"
sh "tar -zxf /tmp/gradle-cache.tgz --directory /tmp"
buildCacheDir = sh(
script: "/tmp/getBuildCache ${params.baseBuildCacheDir} ${params.buildCacheName}",
returnStdout: true).trim()
gradleOpts = gradleOpts + " --gradle-user-home " + buildCacheDir
def releaseOptionCount = 0;
def prepareReleaseOptions = "";
if (params.majorRelease) {
performRelease = true
prepareReleaseOptions = "--releaseType MAJOR"
releaseOptionCount++
}
if (params.minorRelease) {
performRelease = true
prepareReleaseOptions = "--releaseType MINOR"
releaseOptionCount++
}
if (params.patchRelease) {
performRelease = true
prepareReleaseOptions = "--releaseType PATCH"
releaseOptionCount++
}
if (releaseOptionCount > 1) {
error("Only one of major, minor, or patch release options can be selected")
}
if (!params.extraGradleOpts.isEmpty()) {
gradleOpts = gradleOpts + " " + extraGradleOpts
}
sh "git config --global user.email '[email protected]' && git config --global user.name 'Brian Fincher'"
if (performRelease) {
sh 'gradle prepareRelease ' + prepareReleaseOptions + ' ' + gradleOpts
}
}
}
}
stage('Build') {
steps {
sh 'gradle clean build ' + gradleOpts
}
}
stage('Finalize') {
when { expression { performRelease || params.publish } }
steps {
script {
if (performRelease || params.publish ) {
def publishParams = '-PpublishUsername=${publishUsername} -PpublishPassword=${publishPassword}'
publishParams += ' -PpublishSnapshotUrl=http://nexus3:8081/repository/snapshots'
publishParams += ' -PpublishReleaseUrl=http://nexus3:8081/repository/releases'
withCredentials([usernamePassword(credentialsId: 'nexus.fincherhome.com', usernameVariable: 'publishUsername', passwordVariable: 'publishPassword')]) {
sh "gradle publish ${publishParams} ${gradleOpts}"
}
}
if (performRelease) {
withCredentials([sshUserPrivateKey(credentialsId: "bfincher_git_private_key", keyFileVariable: 'keyfile')]) {
sh 'gradle finalizeRelease -PsshKeyFile=${keyfile} ' + gradleOpts
}
}
}
}
}
}
post {
always {
sh("/tmp/releaseBuildCache ${buildCacheDir}")
}
}
}