forked from jfrog/build-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
228 lines (209 loc) · 10.9 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
node('java') {
// Define projects configurations.
def projectsConfig = [
"build-info-extractor-npm": [
releaseVersion: "${EXTRACTOR_RELEASE_VERSION}",
nextVersion: "${EXTRACTOR_NEXT_VERSION}",
buildTasks: 'build-info-extractor-npm:clean build-info-extractor-npm:artifactoryPublish -x test',
releaseTasks: '-PextractorRelease=true build-info-extractor-npm:clean build-info-extractor-npm:artifactoryPublish -x test',
buildName: 'EcoSystemRelease :: build-info-npm-extractor',
tagName: 'build-info-npm-extractor'
],
"build-info-extractor-ivy": [
releaseVersion: "${EXTRACTOR_RELEASE_VERSION}",
nextVersion: "${EXTRACTOR_NEXT_VERSION}",
buildTasks: 'build-info-extractor-ivy:clean build-info-extractor-ivy:artifactoryPublish -x test',
releaseTasks: 'build-info-extractor-ivy:clean build-info-extractor-ivy:artifactoryPublish -x test',
buildName: 'EcoSystemRelease :: build-info-ivy-extractor',
tagName: 'build-info-ivy-extractor'
],
"build-info-extractor-gradle": [
releaseVersion: "${GRADLE_RELEASE_VERSION}",
nextVersion: "${GRADLE_NEXT_VERSION}",
buildTasks: 'build-info-extractor-gradle:clean build-info-extractor-gradle:build build-info-extractor-gradle:artifactoryPublish -x test',
releaseTasks: 'build-info-extractor-gradle:clean build-info-extractor-gradle:build build-info-extractor-gradle:artifactoryPublish -x test',
buildName: 'EcoSystemRelease :: build-info-gradle-extractor',
tagName: 'build-info-gradle-extractor'
],
"build-info-extractor-go": [
releaseVersion: "${EXTRACTOR_RELEASE_VERSION}",
nextVersion: "${EXTRACTOR_NEXT_VERSION}",
buildTasks: 'build-info-extractor-go:clean build-info-extractor-go:artifactoryPublish -x test',
releaseTasks: '-PextractorRelease=true build-info-extractor-go:clean build-info-extractor-go:artifactoryPublish -x test',
buildName: 'EcoSystemRelease :: build-info-go-extractor',
tagName: 'build-info-go-extractor'
],
"build-info-extractor-pip": [
releaseVersion: "${EXTRACTOR_RELEASE_VERSION}",
nextVersion: "${EXTRACTOR_NEXT_VERSION}",
buildTasks: 'build-info-extractor-pip:clean build-info-extractor-pip:artifactoryPublish -x test',
releaseTasks: '-PextractorRelease=true build-info-extractor-pip:clean build-info-extractor-pip:artifactoryPublish -x test',
buildName: 'EcoSystemRelease :: build-info-pip-extractor',
tagName: 'build-info-pip-extractor'
],
"build-info-extractor-nuget": [
releaseVersion: "${EXTRACTOR_RELEASE_VERSION}",
nextVersion: "${EXTRACTOR_NEXT_VERSION}",
buildTasks: 'build-info-extractor-nuget:clean build-info-extractor-nuget:artifactoryPublish -x test',
releaseTasks: '-PextractorRelease=true build-info-extractor-nuget:clean build-info-extractor-nuget:artifactoryPublish -x test',
buildName: 'EcoSystemRelease :: build-info-nuget-extractor',
tagName: 'build-info-nuget-extractor'
],
"build-info-extractor-docker": [
releaseVersion: "${EXTRACTOR_RELEASE_VERSION}",
nextVersion: "${EXTRACTOR_NEXT_VERSION}",
buildTasks: 'build-info-extractor-docker:clean build-info-extractor-docker:artifactoryPublish -x test',
releaseTasks: '-PextractorRelease=true build-info-extractor-docker:clean build-info-extractor-docker:artifactoryPublish -x test',
buildName: 'EcoSystemRelease :: build-info-docker-extractor',
tagName: 'build-info-docker-extractor'
],
"build-info-extractor-maven3": [
releaseVersion: "${EXTRACTOR_RELEASE_VERSION}",
nextVersion: "${EXTRACTOR_NEXT_VERSION}",
buildTasks: 'build-info-extractor-maven3:clean build-info-extractor-maven3:artifactoryPublish -x test',
releaseTasks: '-PextractorRelease=true build-info-extractor-maven3:clean build-info-extractor-maven3:artifactoryPublish -x test',
buildName: 'EcoSystemRelease :: build-info-maven3-extractor',
tagName: 'build-info-extractor-maven3'
],
"build-info": [
releaseVersion: "${EXTRACTOR_RELEASE_VERSION}",
nextVersion: "${EXTRACTOR_NEXT_VERSION}",
buildTasks: 'clean build-info-api:artifactoryPublish build-info-client:artifactoryPublish build-info-extractor:artifactoryPublish build-info-vcs:artifactoryPublish -x test',
releaseTasks: 'clean build-info-api:artifactoryPublish build-info-client:artifactoryPublish build-info-extractor:artifactoryPublish build-info-vcs:artifactoryPublish -x test',
buildName: 'EcoSystemRelease :: build-info-extractor',
tagName: 'build-info-extractor'
]
]
// Prepare build env.
cleanWs()
def jdktool = tool name: "jdk-8u111-linux-x64-jce-unlimited-policy"
env.JAVA_HOME = jdktool
// Get selected projects to build or release.
def selectedProjects = getSelectedProjects(BUILD_PROJECTS, projectsConfig)
// Set gradle configurations.
def deployServer = Artifactory.server 'oss.jfrog.org'
def resolveServer = Artifactory.server 'oss.jfrog.org'
def rtGradle = Artifactory.newGradleBuild()
rtGradle.usesPlugin = true
rtGradle.useWrapper = true
// Clone.
git(
url: 'https://github.com/jfrog/build-info.git',
branch: 'master'
)
stage('Build') {
if ("$EXECUTION_MODE".toString().equals("Build")) {
rtGradle.deployer server: deployServer, repo: 'oss-snapshot-local'
rtGradle.resolver server: resolveServer, repo: 'remote-repos'
rtGradle.deployer.deployIvyDescriptors = false
// If no project is selected - build all of them.
// This functionality is important in order to allow triggering by SCM.
def projectsToBuild = selectedProjects ?: projectsConfig.keySet()
// Build build-info first
if (projectsToBuild.contains("build-info")) {
stage("Building build-info") {
def buildConfig = projectsConfig["build-info"]
buildProject(deployServer, rtGradle, buildConfig.buildName, buildConfig.buildTasks)
projectsToBuild -= "build-info"
}
}
projectsToBuild.each { proj ->
stage("Building ${proj}") {
def buildConfig = projectsConfig[proj]
buildProject(deployServer, rtGradle, buildConfig.buildName, buildConfig.buildTasks)
}
}
}
}
stage('Release Staging') {
if ("$EXECUTION_MODE".toString().equals("Release Staging")) {
def latestReleaseVersion = "${EXTRACTOR_LATEST_RELEASE_VERSION}"
def latestNextVersion = "${EXTRACTOR_LATEST_NEXT_VERSION}"
echo "Bump release version"
if (!selectedProjects) {
error("No projects were selected for Release Staging.")
}
bumpVersion(selectedProjects, projectsConfig, latestReleaseVersion, 'releaseVersion')
sh 'git config user.name "${GITHUB_USERNAME}"'
sh 'git config user.email "[email protected]"'
sh 'git commit -am "[artifactory-release] Release version"'
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: 'GITHUB_API_KEY', var: 'SECRET']]]) {
sh 'git push https://${GITHUB_USERNAME}:${GITHUB_API_KEY}@github.com/jfrog/build-info.git'
}
echo "Build release versions"
rtGradle.deployer server: deployServer, repo: 'oss-release-local'
rtGradle.resolver server: resolveServer, repo: 'remote-repos'
rtGradle.deployer.deployIvyDescriptors = false
// Build build-info first
if (selectedProjects.contains("build-info")) {
buildAndTag("build-info", deployServer, rtGradle, projectsConfig)
selectedProjects -= "build-info"
}
selectedProjects.each { proj ->
buildAndTag(proj, deployServer, rtGradle, projectsConfig)
}
echo "Bump development version"
selectedProjects = getSelectedProjects(BUILD_PROJECTS, projectsConfig)
bumpVersion(selectedProjects, projectsConfig, latestNextVersion, 'nextVersion')
sh 'git commit -am "[artifactory-release] Next development version"'
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: 'GITHUB_API_KEY', var: 'SECRET']]]) {
sh 'git push https://${GITHUB_USERNAME}:${GITHUB_API_KEY}@github.com/jfrog/build-info.git'
}
}
}
}
def buildAndTag(proj, deployServer, rtGradle, projectsConfig) {
stage ("Building ${proj}") {
// Build project.
def buildConfig = projectsConfig[proj]
buildProject(deployServer, rtGradle, buildConfig.buildName, buildConfig.releaseTasks)
// Create tag.
def tag = buildConfig.tagName + "-" + buildConfig.releaseVersion
sh "git tag $tag"
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: 'GITHUB_API_KEY', var: 'SECRET']]]) {
sh 'git push https://${GITHUB_USERNAME}:${GITHUB_API_KEY}@github.com/jfrog/build-info.git --tags'
}
}
}
def getSelectedProjects(projects, projectsConfig) {
def buildProjArr
if (projects?.trim()) {
buildProjArr = projects.split(',') as String[]
if (buildProjArr.contains('ALL')) {
buildProjArr = projectsConfig.keySet()
}
return buildProjArr.toList()
}
}
def buildProject(server, rtGradle, buildName, tasks) {
def buildInfo = Artifactory.newBuildInfo()
buildInfo.name = buildName
rtGradle.run buildFile: 'build.gradle', tasks: tasks, buildInfo: buildInfo
//buildInfo.env.collect()
server.publishBuildInfo buildInfo
}
def bumpVersion(buildProjList, projectsConfig, buildInfoLatestVersion, versionField) {
// Read gradle.properties.
def props = readProperties file: "gradle.properties"
// Update build-info latest version.
props['build-info-latest-release-version'] = buildInfoLatestVersion
// Update required values.
buildProjList.each { proj ->
propsKey = proj + "-version"
versionValue = projectsConfig[proj][versionField]
// Check not null or empty.
if (versionValue?.trim()) {
props[propsKey] = versionValue
} else {
error("the project '" + proj + "' was selected for release but release" +
" version was not provided.")
}
}
// Save new values to gradle.properties.
def content = ""
for(s in props) {
content += s.toString() + "\n"
}
writeFile file: 'gradle.properties', text: content
sh 'cat gradle.properties'
}