This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
forked from phoenixnap/springmvc-raml-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
167 lines (140 loc) · 5.98 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env groovy
final RELEASE_VERSION = 'releaseVersion'
final RELEASE_VERSION_DEFAULT = ''
final DEVELOPMENT_VERSION = 'developmentVersion'
final DEVELOPMENT_VERSION_DEFAULT = ''
final ENABLE_RELEASE = 'enableRelease'
final ENABLE_RELEASE_DEFAULT = false
final GIT_COMMITER_EMAIL = '[email protected]'
final GIT_COMMITER_USERNAME = 'cam-team'
def pipelineProperties = [
parameters([
booleanParam(
name: ENABLE_RELEASE,
description: 'Flag to enable release functionality',
defaultValue: ENABLE_RELEASE_DEFAULT
),
string(
name: RELEASE_VERSION,
description: 'Version to be released',
defaultValue: RELEASE_VERSION_DEFAULT
),
string(
name: DEVELOPMENT_VERSION,
description: 'Version to be used after release',
defaultValue: DEVELOPMENT_VERSION_DEFAULT
)
]),
[
$class: 'BuildDiscarderProperty',
strategy: [$class: 'LogRotator', artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10']
]
]
def isBuildTriggeredByRelease() {
result = sh (script: "git log -1 | grep '\\[maven-release-plugin\\] prepare release'", returnStatus: true)
return (result == 0)
}
node {
checkout scm
def mvnHome = ""
def jdkHome = ""
def branchIs = { branchName -> env.BRANCH_NAME ==~ branchName }
def branchIsNot = { branchName -> !branchIs(branchName) }
properties(pipelineProperties);
withCredentials([
[
$class: 'UsernamePasswordMultiBinding',
credentialsId: 'nexus',
passwordVariable: 'NEXUS_PASS',
usernameVariable: 'NEXUS_USER'
],
[
$class: 'UsernamePasswordMultiBinding',
credentialsId: 'nexus-public',
passwordVariable: 'PUB_NEXUS_PASS',
usernameVariable: 'PUB_NEXUS_USER'
]
]) {
stage("Validate Parameters") {
echo 'Parameter ' + ENABLE_RELEASE + ' = ' + params[ENABLE_RELEASE]
echo 'Parameter ' + RELEASE_VERSION + ' = ' + params[RELEASE_VERSION]
echo 'Parameter ' + DEVELOPMENT_VERSION + ' = ' + params[DEVELOPMENT_VERSION]
if (branchIsNot('master') && params[ENABLE_RELEASE]) {
error('Release functionality is only available from master branch')
}
if (params[ENABLE_RELEASE] && (params[RELEASE_VERSION] == '' || params[DEVELOPMENT_VERSION] == '')) {
error('Release functionality needs both parameters to be set: ' + RELEASE_VERSION + ' and ' + DEVELOPMENT_VERSION)
}
}
stage("Checkout") {
checkoutSCM(scm)
}
stage("Check Release Triggered Build") {
env.RELEASE_TRIGGERED = "false"
if (isBuildTriggeredByRelease()) {
env.RELEASE_TRIGGERED = "true"
echo "Build was triggered by Release"
}
}
if (env.RELEASE_TRIGGERED == "true") {
echo 'Aborting Release triggered Build'
currentBuild.result = 'ABORTED'
return
}
stage("Set Maven configuration") {
env.MAVEN_SETTINGS_PATH = '.jenkins/settings.xml'
env.MAVEN_SETTINGS_PATH
mvnHome = tool name: 'maven-3.3.9', type: 'hudson.tasks.Maven$MavenInstallation'
jdkHome = tool name: 'Java 8', type: 'hudson.model.JDK'
}
stage("Build & Test") {
withEnv(["PATH=${jdkHome}/bin:${mvnHome}/bin:${env.PATH}", "M2_HOME=${mvnHome}"]) {
echo sh(script: 'env|sort', returnStdout: true)
sh "mvn -s ${env.MAVEN_SETTINGS_PATH} clean verify -U"
}
}
stage ("Nexus IQ") {
withEnv(["PATH=${jdkHome}/bin:${mvnHome}/bin:${env.PATH}", "M2_HOME=${mvnHome}"]) {
nexusIQScan("springmvc-raml-plugin",
"http://nexus-iq-0:8070",
"target/springmvc-raml-plugin-*.jar")
}
}
stage("Regular Deploy") {
if (branchIs('master') && !params[ENABLE_RELEASE]) {
echo 'Running Regular Deploy'
withEnv(["PATH=${jdkHome}/bin:${mvnHome}/bin:${env.PATH}", "M2_HOME=${mvnHome}"]) {
echo sh(script: 'env|sort', returnStdout: true)
sh "mvn -s ${env.MAVEN_SETTINGS_PATH} -U clean deploy -DskipTests"
}
} else if (branchIs('develop')){
echo 'Running SNAPSHOT Deploy'
withEnv(["PATH=${jdkHome}/bin:${mvnHome}/bin:${env.PATH}", "M2_HOME=${mvnHome}"]) {
echo sh(script: 'env|sort', returnStdout: true)
sh "mvn -s ${env.MAVEN_SETTINGS_PATH} -U clean deploy -DskipTests -DaltReleaseDeploymentRepository='fake-repo::default::http://asd.example.com/api/maven' "
}
} else {
echo 'Skipping Regular Deploy'
}
}
stage("Release") {
if (branchIs('master') && params[ENABLE_RELEASE]) {
echo 'Running Release'
withEnv(["PATH=${jdkHome}/bin:${mvnHome}/bin:${env.PATH}", "M2_HOME=${mvnHome}"]) {
echo sh(script: 'env|sort', returnStdout: true)
sh "git config user.email ${GIT_COMMITER_EMAIL}"
sh "git config user.name '${GIT_COMMITER_USERNAME}'"
sh ("mvn -s ${env.MAVEN_SETTINGS_PATH} -U" +
" -DreleaseVersion=${params[RELEASE_VERSION]}" +
" -DdevelopmentVersion=${params[DEVELOPMENT_VERSION]}" +
" -Dgoals=deploy" +
" -Darguments='-DskipTests'" +
" release:clean release:prepare release:perform"
)
}
} else {
echo 'Skipping Release'
}
}
}
}