-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
149 lines (128 loc) · 7.1 KB
/
Jenkinsfile
File metadata and controls
149 lines (128 loc) · 7.1 KB
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
// Project's POM file
def applicationName = 'JavaTemplates'
def projectPom = './pom.xml'
// Email extension plugin base parameters
def emailextConfig = [
to: 'pierre.lupien@hrsdc-rhdcc.gc.ca,ahmad.shahid@hrsdc-rhdcc.gc.ca', //comma-separated lits of addresses
from: 'Jenkins-CI <jenkins-ci@jade-build.intra.dev>',
body: '${SCRIPT, template="groovy-html.template"}', //for details on body: https://wiki.jenkins.io/display/JENKINS/Email-ext+plugin#Email-extplugin-Scriptcontent
mimeType: 'text/html'
]
pipeline {
agent any; //any: Run on any available agent - agent is same for all stages
//none: No top-level setting. Each stage must declare its own agent. Needed for non-blocking input.
options {
buildDiscarder logRotator(artifactNumToKeepStr: '5', numToKeepStr: '10')
disableConcurrentBuilds()
timestamps()
}
tools {
maven('maven')
git('git')
ant('Ant')
jdk('OpenJDK11')
}
parameters {
string(defaultValue: '', description: 'Deploy version (e.g. 2.0.1) Leave blank to use version form source code.', name: 'DEPLOY_VERSION', trim: true)
}
stages {
stage('Project Artifact Version Check') {
steps {
script {
def projectModel = readMavenPom(file: projectPom)
if (params.DEPLOY_VERSION.isEmpty()) {
// No version parameter specified: make sure the one from pom file is Snapshot
if (!projectModel.version.endsWith('-SNAPSHOT')) {
currentBuild.result = 'ABORTED'
error('Building non-SNAPSHOT versions must be explicitly triggerd by specifying the DEPLOY_VERSION parameter.')
}
}
else {
// A version parameter was specified, perform some checks
if (params.DEPLOY_VERSION.contains(" ")) {
currentBuild.result = 'ABORTED'
error('DEPLOY_VERSION must not contain spaces.')
}
if (!params.DEPLOY_VERSION.toUpperCase().endsWith('-SNAPSHOT')) {
//RELEASE build: make sure our dependencies are not snapshots
def mavenDesc = Artifactory.mavenDescriptor()
mavenDesc.pomFile = projectPom
if (mavenDesc.hasSnapshots()) {
currentBuild.result = 'ABORTED'
error('Snapshot(s) detected in dependencies. This is a release build. Snapshot dependencies are not allowed.')
}
}
}
} //of script
} //of steps
} //of stage
stage('Release build confirmation') {
when {
beforeInput true
expression {
return (!params.DEPLOY_VERSION.isEmpty()) && (!params.DEPLOY_VERSION.toUpperCase().endsWith('-SNAPSHOT'));
}
}
input {
message "About to deploy RELEASE version [${params.DEPLOY_VERSION}] to Artifactory, are you sure?"
ok 'Yes, deploy!'
submitterParameter 'DEPLOY_SUBMITTER'
}
steps {
script {
sh(script: "echo Release build authorized.")
}
}
}
stage('Build and Deploy') {
steps {
script {
def git = tool('git')
def gitCommitId = sh(script: "'${git}' rev-parse HEAD", returnStdout: true).trim()
withAnt(ant: 'Ant', jdk: 'OpenJDK11') {
withMaven(maven: 'maven', jdk: 'OpenJDK11') {
//---[ If an explicit version was specified, override source's versions
if (!params.DEPLOY_VERSION.isEmpty()) {
sh(script: "ant -buildfile ./builds/build-setprojectversion.xml \"-Dgocwebtemplate.build.version=${params.DEPLOY_VERSION}\"")
}
//---[ Build/deploy main projects
sh(script: "mvn --batch-mode --errors --update-snapshots -Dbuild_number=${BUILD_NUMBER} -Dbuild_git_commitid=${gitCommitId} --file ${projectPom} clean deploy")
//---[ Build/deploy archetypes
sh(script: "ant -buildfile ./builds/build-archetypes.xml")
//---[ If this is a release version, build ZIP file for external clients
if ((!params.DEPLOY_VERSION.isEmpty()) && (!params.DEPLOY_VERSION.toUpperCase().endsWith('-SNAPSHOT'))) {
sh(script: "ant -buildfile ./builds/build-release.xml")
}
}
}
}
}
}
}
post {
always { //Always run, regardless of build status
archiveArtifacts(artifacts: "gocwebtemplate-*/**/target/*.?ar", allowEmptyArchive: true, fingerprint: true)
archiveArtifacts(artifacts: "builds/target/gocwebtemplate-*-${params.DEPLOY_VERSION}.zip", allowEmptyArchive: true, fingerprint: true)
junit(testResults: "gocwebtemplate-*/**/target/surefire-reports/TEST-*.xml", allowEmptyResults: true)
emailext(to: emailextConfig.to,
from: emailextConfig.from,
body: emailextConfig.body,
mimeType: emailextConfig.mimeType,
subject: "Jenkins Build [${currentBuild.fullDisplayName}] Built - [${currentBuild.result}] for application [${applicationName}]")
}
regression { //Run if the current builds status is worse than the previous builds status
emailext(to: emailextConfig.to,
from: emailextConfig.from,
body: emailextConfig.body,
mimeType: emailextConfig.mimeType,
subject: "Jenkins Build [${currentBuild.fullDisplayName}] Regression - [${currentBuild.result}] for application [${applicationName}]")
}
fixed { //Run if the previous build was not successful and the current builds status is "Success"
emailext(to: emailextConfig.to,
from: emailextConfig.from,
body: emailextConfig.body,
mimeType: emailextConfig.mimeType,
subject: "Jenkins Build [${currentBuild.fullDisplayName}] Success - [${currentBuild.result}] for application [${applicationName}]")
}
}
}