-
-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathJenkinsfile
180 lines (150 loc) · 9.07 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
/*
This Jenkins pipeline does a full release build of openhab-distro including the release of all openHAB dependencies.
It also includes all required SCM operations.
*/
try {
library identifier: 'openhab@main', retriever: modernSCM([$class: 'GitSCMSource', id: 'be5932e8-b631-4947-b26a-8dfa1802f1af', remote: env.GIT_BASE_URL + '/infrastructure'])
currentBuild.displayName = OH_RELEASE_VERSION + ' (#' + env.BUILD_NUMBER + ')'
if(env.SANDBOX?.toBoolean() && !env.SKIP_SANDBOX_RESET?.toBoolean() && env.ALT_RELEASE_REPO_ID?.length() > 0) {
node {
clearOpenhabMavenRepository env.ALT_RELEASE_REPO_ID + "/org"
}
}
node {
deleteDir()
releaseComponent('openhab-core', false, env.OH_BRANCH)
}
// checkpoint "openHAB Core released"
node {
deleteDir()
releaseComponent('openhab-addons', true, env.OH_BRANCH)
releaseComponent('org.openhab.binding.zwave', true, env.OH_BRANCH)
releaseComponent('org.openhab.binding.zigbee', true, env.OH_BRANCH)
releaseComponent('openhab-webui', true, env.OH_BRANCH)
}
// checkpoint "openHAB Add-Ons released"
node {
deleteDir()
releaseComponent('openhab-distro', true, env.OH_BRANCH)
def releaseVersion = env.OH_RELEASE_VERSION
def distributions = 'openhab-distro/distributions'
archiveArtifacts artifacts: "${distributions}/openhab/target/openhab-${releaseVersion}.*, ${distributions}/openhab-addons/target/openhab-addons-${releaseVersion}.kar, ${distributions}/openhab-demo/target/openhab-demo-${releaseVersion}.*"
}
if(!env.SANDBOX?.toBoolean()) {
build wait: false, job: 'openHAB-Docker', parameters: [string(name: 'OPENHAB_VERSION', value: "$OH_RELEASE_VERSION")]
}
}
catch(Exception e) {
notifyFailedOpenhabBuild()
throw e
}
if("FAILURE".equals(currentBuild.previousBuild?.result)) {
notifyBackToNormalOpenhabBuild()
}
def releaseComponent(componentName, updateParent, repoBranch) {
def branch = repoBranch ?: 'main'
releaseOpenHabComponent(componentName, branch, env.OH_RELEASE_VERSION, env.OH_NEXT_VERSION, updateParent, true)
}
def releaseOpenHabComponent(componentName, branch, releaseVersion, nextVersion, updateParent, updateProperties) {
def gitBaseUrl = env.GIT_BASE_URL
def gitRepoUrl = gitBaseUrl + '/' + componentName
resetOpenhabFork(gitBaseUrl, componentName, releaseVersion)
withCredentials([usernamePassword(credentialsId: env.GIT_CREDENTIALS_ID, passwordVariable: 'githubPassword', usernameVariable: 'githubUser')]) {
dir(componentName) {
deleteDir()
checkout([$class: 'GitSCM', branches: [[name: '*/' + branch]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'LocalBranch', localBranch: branch], [$class: 'CloneOption', depth: 0, noTags: true, reference: '', shallow: false], [$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: false, recursiveSubmodules: true, reference: '', trackingSubmodules: true]], submoduleCfg: [], userRemoteConfigs: [[url: gitRepoUrl ]]])
def isMilestoneBuild = releaseVersion.contains("M") || releaseVersion.contains("RC")
def mvnReleaseOptions = ""
def mvnSnapshotOptions = ""
def mvnOptionsMap = [:]
mvnOptionsMap["build"] = '-DreleaseArgs=skipTests=true,skipChecks=true,spotless.check.skip=true -DskipChecks=true -DskipTests=true -DgenerateBackupPoms=false -Dspotless.check.skip=true' //
mvnOptionsMap["unleash"] = "-Dunleash.releaseVersion=${releaseVersion} -Dunleash.developmentVersion=${nextVersion}-SNAPSHOT -Dunleash.scmUsername="+ githubUser + " -Dunleash.scmPassword=" + githubPassword
if(isMilestoneBuild) {
mvnOptionsMap["type"] = "-Dmilestone"
} else {
mvnOptionsMap["type"] = "-Drelease"
}
if(env.SANDBOX?.toBoolean()) {
mvnOptionsMap["sandbox"] = "-P sandbox"
}
if(env.ALT_RELEASE_REPO_ID?.length() > 0) {
mvnReleaseOptions += "-DaltDeploymentRepository=" + env.ALT_RELEASE_REPO_ID + '::default::' + env.ALT_RELEASE_REPO_URL
}
if(env.ALT_SNAPSHOT_REPO_ID?.length() > 0) {
mvnSnapshotOptions += "-DaltDeploymentRepository=" + env.ALT_SNAPSHOT_REPO_ID + '::default::' + env.ALT_SNAPSHOT_REPO_URL
}
mvnOptionsMap["global"] = env.GLOBAL_MAVEN_CLI_OPTS + " " + env.MAVEN_EXTRA_OPTS
def mvnOptions = mvnOptionsMap.values().join(" ")
mvnSnapshotOptions = mvnOptions + " " + mvnSnapshotOptions
mvnReleaseOptions = mvnOptions + " " + mvnReleaseOptions
stage(componentName + ": Release") {
writeUnleashWorkflows()
withMaven(jdk: 'OpenJDK 11', maven: 'maven (latest)', mavenOpts: '-Xms512m -Xmx2048m', mavenLocalRepo: '.repository', globalMavenSettingsConfig: env.MAVEN_GLOBAL_SETTINGS, options: [artifactsPublisher(disabled: true)]) {
//Set release versions
if(updateProperties) {
sh "mvn versions:set-property -Dproperty=ohc.version -DnewVersion="+ env.OH_RELEASE_VERSION +" " + mvnOptions
sh "mvn versions:set-property -Dproperty=oha.version -DnewVersion="+ env.OH_RELEASE_VERSION +" " + mvnOptions
}
if(updateParent) {
sh "mvn versions:update-parent -DparentVersion=[" + env.OH_RELEASE_VERSION +"] " + mvnOptions
}
sh "mvn unleash:perform -Dworkflow=unleash.phase1.workflow " + mvnOptions
}
withMaven(jdk: 'OpenJDK 21', maven: 'maven (latest)', mavenOpts: '-Xms512m -Xmx2048m', mavenLocalRepo: '.repository', globalMavenSettingsConfig: env.MAVEN_GLOBAL_SETTINGS, options: [artifactsPublisher(disabled: true)]) {
sh "mvn deploy " + mvnReleaseOptions
}
withMaven(jdk: 'OpenJDK 11', maven: 'maven (latest)', mavenOpts: '-Xms512m -Xmx2048m', mavenLocalRepo: '.repository', globalMavenSettingsConfig: env.MAVEN_GLOBAL_SETTINGS, options: [artifactsPublisher(disabled: true)]) {
//Tag SCM
sh "mvn unleash:perform -Dworkflow=unleash.phase2.workflow " + mvnOptions
}
//Prevent wrong scm tag from being checked in
sh 'git reset --hard ' + branch
}
stage(componentName + ": Prepare next version") {
//Set next development versions
if(!releaseVersion.startsWith(nextVersion)) {
withMaven(jdk: 'OpenJDK 11', maven: 'maven (latest)', mavenOpts: '-Xms512m -Xmx2048m', mavenLocalRepo: '.repository', globalMavenSettingsConfig: env.MAVEN_GLOBAL_SETTINGS, options: [artifactsPublisher(disabled: true)]) {
if(updateParent) {
sh "mvn versions:update-parent -DallowSnapshots=true -DparentVersion=[" + env.OH_NEXT_VERSION +"-SNAPSHOT] " + mvnOptions
}
if(updateProperties) {
sh "mvn versions:set-property -Dproperty=ohc.version -DnewVersion="+ env.OH_NEXT_VERSION +"-SNAPSHOT " + mvnOptions
sh "mvn versions:set-property -Dproperty=oha.version -DnewVersion="+ env.OH_NEXT_VERSION +"-SNAPSHOT " + mvnOptions
sh "mvn versions:set-property -Dproperty=repo.version -DnewVersion="+ env.OH_NEXT_VERSION.replace('[0-9]$', 'x ') + mvnOptions
}
sh "mvn unleash:perform -Dworkflow=unleash.phase3.workflow " + mvnOptions
}
withMaven(jdk: 'OpenJDK 21', maven: 'maven (latest)', mavenOpts: '-Xms512m -Xmx2048m', mavenLocalRepo: '.repository', globalMavenSettingsConfig: env.MAVEN_GLOBAL_SETTINGS, options: [artifactsPublisher(disabled: true)]) {
sh "mvn deploy " + mvnSnapshotOptions
}
}
}
}
}
}
def writeUnleashWorkflows() {
def unleashPhase1Workflow = """
storeScmRevision
checkProjectVersions
checkParentVersions
checkPlugins
checkPluginDependencies
prepareVersions
#checkAether
setReleaseVersions
"""
sh 'echo "' + unleashPhase1Workflow +'" > unleash.phase1.workflow'
def unleashPhase2Workflow = """
prepareVersions
checkForScmChanges
checkDependencies
tagScm
"""
sh 'echo "' + unleashPhase2Workflow +'" > unleash.phase2.workflow'
def unleashPhase3Workflow = """
prepareVersions
checkForScmChanges
setDevVersion
"""
sh 'echo "' + unleashPhase3Workflow +'" > unleash.phase3.workflow'
}