forked from forcedotcom/Salesforce-CDP-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
188 lines (159 loc) · 5.22 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
@Library('sfci-pipeline-sharedlib@master') _
import net.sfdc.dci.BuildUtils
import net.sfdc.dci.MavenUtils
import net.sfdc.dci.LogUtil
import net.sfdc.dci.CodeCoverageUtils
env.GUS_TEAM_NAME = "CDP Query Service"
env.GUS_TEAM_EMAIL = "[email protected]"
env.RELEASE_BRANCHES = ['master']
// branches that will publish SNAPSHOT releases from the a360 instance
def SNAPSHOT_BRANCHES = []
// Careful of changing the default, or relying on dynamically resolving them
// https://issues.jenkins-ci.org/browse/JENKINS-41929
def buildParameters = {
parameters([
booleanParam(
name: 'SKIP_TESTS',
description: 'Do you want to skip the tests?',
defaultValue: false
),
booleanParam(
name: 'PUSH_TO_NEXUS',
description: 'Do we want to put artifact in nexus',
defaultValue: false
)
])
}
def releaseParameters = {
parameters([
booleanParam(
name: 'SKIP_TESTS',
description: 'Do you want to skip the tests?',
defaultValue: false
),
booleanParam(
name: 'PUSH_TO_NEXUS',
description: 'Do we want to put artifact in nexus',
defaultValue: false //Should this be true for release branch?
),
booleanParam(
name: 'IS_RELEASE',
description: 'Do you want to release?',
// Check it on the UI to release with automatic versioning.
defaultValue: false
),
string( defaultValue: MavenUtils.getDefaultReleaseVersion(this),
description: 'Enter the release version',
name: 'RELEASE_VERSION'
),
string( defaultValue: "",
description: 'Next Release Version, e.g. RELEASE_VERSION=cdp_2020.4a -> NEXT_RELEASE_VERSION=cdp_2020.4b-SNAPSHOT',
name: 'NEXT_RELEASE_VERSION'
)
])
}
/*** TESTING CONFIG ***/
env.CODE_COVERAGE_THRESHOLD = 0
// These patterns must mirror those found in the pom.xml under the jacoco config
def inclusionPatterns = [
]
def exclusionPatterns = [
]
// Reference: https://git.soma.salesforce.com/dci/sfci-pipeline-sharedlib/blob/master/src/net/sfdc/dci/v1/ExecutePipeline.groovy
def envDef = [
releaseParameters: releaseParameters,
buildParameters: buildParameters,
buildImage: 'ops0-artifactrepo1-0-prd.data.sfdc.net/dci/centos7-sfci-jdk11-maven:80795e9',
useOpenJDK: true,
emailTo: env.GUS_TEAM_EMAIL,
stopSuccessEmail: true
// pipelineTriggerCron: { cron('@daily') }
]
def getMavenVersion(isSnapshotBuild) {
// Always use the version from pom.xml
def version = MavenUtils.getDefaultVersion(this)
if (version == null) {
failAndThrow(new Exception('Version resolved as null!'))
}
if (isSnapshotBuild && !version.endsWith('-SNAPSHOT')) {
version += '-SNAPSHOT'
}
// Overwrite the RELEASE_VERSION param
env.RELEASE_VERSION = version
return version
}
executePipeline(envDef) {
def isRelease = env.IS_RELEASE == 'true'
def toNexus = env.PUSH_TO_NEXUS == 'true'
def runTests = env.SKIP_TESTS != 'true'
def isReleaseBuild = BuildUtils.isReleaseBuild(env)
def isPullRequestBuild = BuildUtils.isPullRequestBuild(env)
def isSnapshotBuild = SNAPSHOT_BRANCHES.contains(env.BRANCH_NAME)
def version = getMavenVersion(isSnapshotBuild)
LogUtil.info(this, "Config for build: isRelease: ${isRelease}, isReleaseBuild: ${isReleaseBuild}, BRANCH_NAME: ${env.BRANCH_NAME}, isPullRequestBuild: ${isPullRequestBuild}, isSnapshotBuild: ${isSnapshotBuild}, version: ${version}")
stage('Init') {
checkout scm
//Magic value, hidden logic around this parameter.
env.RELEASE = 'true'
currentBuild.displayName = "#${BUILD_NUMBER}: ${version}"
mavenInit()
}
service: {
stage('Compile') {
mavenBuild([
maven_goals: 'clean compile'
])
}
LogUtil.info(this, "Compile stage completed")
stage('Verify') {
mavenBuild([
maven_goals: 'deploy',
maven_args: '-Prelease ' + (runTests ? '-Pcode-coverage-jacoco' : '-DskipTests')
])
if(runTests) {
def coverage_config = [
tool_name: 'jacoco',
gus_team_name: env.GUS_TEAM_NAME,
failing_threshold: env.CODE_COVERAGE_THRESHOLD,
inclusion_patterns: inclusionPatterns.join(','),
exclusion_patterns: exclusionPatterns.join(',')
]
LogUtil.info(this, "Validating code coverage")
CodeCoverageUtils.publishAndValidateCoverageReport(this, coverage_config)
if(isRelease) {
LogUtil.info(this, "Uploading code coverage report to GUS")
CodeCoverageUtils.uploadReportForGusDashboard(this, coverage_config)
}
} else {
mavenBuild([
maven_goals: 'deploy',
maven_args: '-Prelease -DskipTests'
])
}
}
LogUtil.info(this, "Verify stage completed")
if(BuildUtils.isReleaseBuild(env)) {
stage('Build') {
def maven_config = [
maven_goals: 'deploy',
maven_args: '-Prelease -DskipTests'
]
if(isRelease) {
mavenReleasePrepare(maven_config)
if(toNexus) {
mavenReleasePerform(maven_config)
}
} else if (toNexus) {
mavenDeploySnapshots(maven_config)
} else {
mavenBuild(maven_config)
}
}
}
}
if(isRelease) {
stage('GUS compliance') {
git2gus()
}
}
}