-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
152 lines (135 loc) · 5.69 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
#!groovy
nodeWithProperWorkspace {
String mvnTool = tool name: 'Maven 3.2.5', type: 'hudson.tasks.Maven$MavenInstallation'
stage('Checkout') {
checkout scm
if (isMaster()) {
// git by default checks out detached, we need a local branch
sh "git checkout $env.BRANCH_NAME" // workaround for https://issues.jenkins-ci.org/browse/JENKINS-31924
sh 'git fetch --prune origin +refs/tags/*:refs/tags/*' // delete all local tags
sh "git reset --hard origin/master"
sh "git clean -ffdx"
} else {
sh "git clean -ffd"
}
}
if (isMaster() && isVersionTag()) {
// Workaround: we don't want infinite releases.
echo "Aborting build as the current commit on master is already tagged."
currentBuild.displayName = "checkout-only"
currentBuild.result = 'UNSTABLE' // mark this build run as unstable so that perma-link to stable build artifact points to the last product built
return
}
def preReleaseVersion = getCurrentVersion()
if (isMaster()) {
prepareRelease()
}
stage('Build target platform') {
withMavenEnv {
gradle 'buildTarget'
}
}
stage('Build Web Components') {
withMavenEnv {
gradle 'preBuildWeb'
}
}
stage('Build') {
withMavenEnv(["MAVEN_OPTS=-Xms512m -Xmx2g", "TE_MAVEN_HOME=${mvnTool}"]) {
withXvfb {
gradle 'build'
}
}
}
// workaround for now to speed-up the build: only build the product on develop, master and branches that end with -with-product
def buildProduct = env.BRANCH_NAME == "develop" || env.BRANCH_NAME.endsWith("-with-product") || isMaster()
if (buildProduct) {
stage('Build product') {
withMavenEnv(["MAVEN_OPTS=-Xms512m -Xmx2g", "TE_MAVEN_HOME=${mvnTool}"]) {
step([$class: 'CopyArtifact',
filter: 'target/rrd*.jar',
fingerprintArtifacts: true,
flatten: true,
projectName: 'rrd-antlr4',
selector: [$class: 'StatusBuildSelector',
stable: false],
target: 'docs'])
gradle 'createAllRRDs'
gradle 'buildProduct'
}
}
}
if (isMaster()) {
stage('Deploy') {
withMavenEnv(["TE_MAVEN_HOME=${mvnTool}"]) {
gradle 'deploy'
}
}
postRelease(preReleaseVersion)
}
stage('Archive results') {
// archive all written screenshots
archiveArtifacts artifacts: 'rcp/org.testeditor.rcp4.uatests/screenshots/**/*.png', fingerprint: true
if (buildProduct) {
archive '**/target/products/*.zip'
archiveArtifacts artifacts: 'docs/output/**/*.png, docs/output/**/*.html', fingerprint: true
}
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
codecov('codecov_test-editor-xtext')
}
}
void prepareRelease() {
stage('Prepare release') {
// Remove SNAPSHOT version
echo 'Removing SNAPSHOT from target platform version'
def String noSnapshotVersion = '\\${parsedVersion.majorVersion}.\\${parsedVersion.minorVersion}.\\${parsedVersion.incrementalVersion}'
setVersion(noSnapshotVersion, 'target-platform/pom.xml', 'org.testeditor.releng.target.parent')
echo 'Removing SNAPSHOT from test-editor version'
setVersion(noSnapshotVersion, 'pom.xml', 'org.testeditor.releng.parent')
// Set the display name for the job to the version
String version = getCurrentVersion()
currentBuild.displayName = version
echo "Version to release is: $version"
}
}
String getCurrentVersion() {
def pom = readMavenPom file: 'pom.xml'
return pom.parent.version
}
void postRelease(String preReleaseVersion) {
stage('Tag release') {
def version = "v${getCurrentVersion()}"
echo "Tagging release as $version"
sh "git add ."
sh "git commit -m '[release] $version'"
sh "git tag $version"
// workaround: cannot push without credentials using HTTPS => push using SSH
sh "git remote set-url origin ${getGithubUrlAsSsh()}"
sh "git push origin master --tags"
}
stage('Increment develop version') {
sh "git checkout develop"
sh "git fetch origin"
sh "git reset --hard origin/develop"
def developVersion = getCurrentVersion()
if (developVersion == preReleaseVersion) {
sh "git merge origin/master"
def nextSnapshotVersion = '\\${parsedVersion.majorVersion}.\\${parsedVersion.nextMinorVersion}.0-SNAPSHOT'
setVersion(nextSnapshotVersion, 'target-platform/pom.xml', 'org.testeditor.releng.target.parent')
setVersion(nextSnapshotVersion, 'pom.xml', 'org.testeditor.releng.parent')
sh "git add ."
sh "git commit -m '[release] set version ${getCurrentVersion()}'"
sh "git push origin develop"
} else {
echo "Version on develop not incremented as it differs from the preReleaseVersion."
}
}
}
void setVersion(String newVersion, String rootPom = null, String artifacts = null) {
String mvnTool = tool name: 'Maven 3.2.5', type: 'hudson.tasks.Maven$MavenInstallation'
withMavenEnv(["TE_MAVEN_HOME=${mvnTool}"]) {
def goals = 'build-helper:parse-version org.eclipse.tycho:tycho-versions-plugin:set-version'
def pom = rootPom ? "-f $rootPom " : ''
sh "mvn $pom$goals -Dartifacts=$artifacts -DnewVersion=$newVersion -Dtycho.mode=maven"
}
}