Compare commits

2 Commits

Author SHA1 Message Date
44aaeef061 Fixed issued with pom.xml
All checks were successful
Locusworks Team/eight-track/pipeline/head This commit looks good
2020-05-22 20:41:35 +01:00
275a29a78d updated pom.xml
Some checks failed
Locusworks Team/eight-track/pipeline/head There was a failure building this commit
2020-05-22 20:35:59 +01:00
3 changed files with 104 additions and 70 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@
/key.bin /key.bin
/logs/ /logs/
/conf/ /conf/
.metadata/

140
Jenkinsfile vendored
View File

@ -1,7 +1,18 @@
#!groovy #!groovy
// Required Jenkins plugins:
// https://wiki.jenkins-ci.org/display/JENKINS/Timestamper
// https://wiki.jenkins-ci.org/display/JENKINS/Static+Code+Analysis+Plug-ins
// https://wiki.jenkins-ci.org/display/JENKINS/Checkstyle+Plugin ?
// https://wiki.jenkins-ci.org/display/JENKINS/FindBugs+Plugin
// https://wiki.jenkins-ci.org/display/JENKINS/PMD+Plugin ?
// https://wiki.jenkins-ci.org/display/JENKINS/DRY+Plugin ?
// https://wiki.jenkins-ci.org/display/JENKINS/Task+Scanner+Plugin
// https://wiki.jenkins-ci.org/display/JENKINS/Javadoc+Plugin
// https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin ?
init()
init()
def branch_name def branch_name
def branch_name_base def branch_name_base
@ -23,7 +34,8 @@ def init() {
build_url = env.BUILD_URL build_url = env.BUILD_URL
job_name = "${env.JOB_NAME}" job_name = "${env.JOB_NAME}"
branch_name = env.BRANCH_NAME branch_name = env.BRANCH_NAME
persist = branch_name branch_name_docker = branch_name.replaceAll(/\//,'.')
persist = "/var/lib/jenkins/PERSIST/${branch_name_docker}"
// execute the branch type specific pipeline code // execute the branch type specific pipeline code
try { try {
@ -31,52 +43,44 @@ def init() {
if (branch_name.indexOf('release/')==0) build_type='release' if (branch_name.indexOf('release/')==0) build_type='release'
if (branch_name.indexOf('feature/')==0) build_type='feature' if (branch_name.indexOf('feature/')==0) build_type='feature'
if (branch_name.indexOf('develop')==0) build_type='develop' if (branch_name.indexOf('develop')==0) build_type='develop'
if (branch_name.indexOf('hotfix')==0) build_type='hotfix'
if (branch_name.indexOf('bugfix')==0) build_type='bugfix'
if (branch_name.indexOf('master')==0) build_type='master' if (branch_name.indexOf('master')==0) build_type='master'
if (branch_name.indexOf('hotfix/')==0) build_type='hotfix'
if (branch_name.indexOf('bugfix/')==0) build_type='bugfix' // common pipeline elements
node('master') {
Initialize()
SetVersion(build_type)
print_vars() // after SetVersion - all variables now defined
set_result('INPROGRESS')
Build() // builds database via flyway migration
}
switch(build_type) { if (branch_name.indexOf('develop')==0) {
case ~/feature/: node('master') {
case ~/hotfix/: Deploy();
case ~/bugfix/: }
case ~/master/: } else if (branch_name.indexOf('release/')==0) {
case ~/develop/: node('master') {
CommonBuild(); Deploy();
break; }
case ~/release/:
CommonBuild();
Deploy();
break;
default:
throw "unsupported branch type: ${branch_name}"
} }
node('master') { node('master') {
set_result('SUCCESS') set_result('SUCCESS')
} }
} catch (err) { } catch (err) {
node() { node() {
set_result('FAILURE') set_result('FAILURE')
} }
throw err throw err
} }
} }
def CommonBuild() {
// common pipeline elements
node('master') {
Initialize()
SetVersion(build_type)
print_vars() // after SetVersion - all variables now defined
set_result('INPROGRESS')
Build()
}
}
def Build() { def Build() {
stage ('build') { stage ('build') {
mvn_alt("install -DskipTests=true -Dbuild.revision=${git_commit}") mvn "install -DskipTests=true -Dbuild.revision=${git_commit}"
step([$class: 'ArtifactArchiver', artifacts: '**/target/*.jar', fingerprint: true]) step([$class: 'ArtifactArchiver', artifacts: '**/target/*.jar', fingerprint: true])
} }
} }
@ -92,10 +96,8 @@ def Initialize() {
} }
def Deploy() { def Deploy() {
node('master') { stage ('deploy') {
stage ('deploy') { mvn "deploy -DskipTests=true -Dbuild.number=${build_number} -Dbuild.revision=${git_commit}"
mvn_alt("deploy -DskipTests=true -Dbuild.number=${build_number} -Dbuild.revision=${git_commit}")
}
} }
} }
@ -105,17 +107,19 @@ def getSha1() {
return sha1 return sha1
} }
def mvn_initial(args) { def mvn(args) {
mvn_alt(args) withMaven(
maven: 'maven-3.6.1',
globalMavenSettingsConfig: 'locusworks-settings'
) {
sh "mvn ${args}"
}
} }
def mvn_alt(args) { def mvn_initial(args) {
// add maven tools to path before calling maven mvn(args)
withMaven(maven: 'maven-3.6.1', jdk: 'jdk1.8.0_221', mavenSettingsConfig: 'maven_settings') {
writeFile file: '.skip-task-scanner', text: ''
writeFile file: '.skip-publish-junit-results', text: ''
sh "mvn ${args}"
}
} }
def set_result(status) { def set_result(status) {
@ -130,10 +134,13 @@ def set_result(status) {
} else { } else {
error ("unknown status") error ("unknown status")
} }
// save in persistence file for access the status page
// make sure the directory exists first
sh "mkdir -p $persist && echo $status > $persist/build.result"
} }
def notify_bitbucket(state) { def notify_bitbucket(state) {
echo "notify bitbucket, state = $state, commit: ${git_commit}"
} }
def print_vars() { def print_vars() {
@ -146,35 +153,34 @@ def print_vars() {
echo "display_name = ${currentBuild.displayName}" echo "display_name = ${currentBuild.displayName}"
echo "version = ${version}" echo "version = ${version}"
echo "git_commit = ${git_commit}" echo "git_commit = ${git_commit}"
} }
def SetVersion( v ) { def SetVersion( v ) {
stage ('set version') { stage ('set version') {
echo "set version ${v}" echo "set version ${v}"
branch_name_base = (branch_name =~ /([^\/]+$)/)[0][0] branch_name_base = (branch_name =~ /([^\/]+$)/)[0][0]
if ( v == 'release' ) {
switch(build_type) { // for release branches, where the branch is named "release/1.2.3",
case ~/develop/: // derive the version and display name derive from the numeric suffix and append the build number
version = build_number + '-SNAPSHOT' // 3.2.1.100
currentBuild.displayName = version version = branch_name_base + "." + build_number + "-RELEASE";
break; //version = branch_name.substring('release/'.length()) + "." + build_number
case ~/release/: currentBuild.displayName = version
// for release branches, where the branch is named "release/1.2.3", } else if (v == 'develop') {
// derive the version and display name derive from the numeric suffix and append the build number version = branch_name_base + "." + build_number + "-SNAPSHOT";
// 3.2.1.100 currentBuild.displayName = version
version = branch_name_base + '.' + build_number + '-RELEASE' } else {
currentBuild.displayName = version // for all other branches the version number is 0 with an appended build number
break; // and for the display name use the jenkins default #n and add the branch name
default: // #101 - feature/user/foo
// for all other branches the version number is 0 with an appended build number //version = '0.' + build_number
// and for the display name use the jenkins default #n and add the branch name version = branch_name_base + "." + build_number
version = branch_name_base + "." + build_number currentBuild.displayName = "#" + build_number + " - " + branch_name_base
currentBuild.displayName = "#" + build_number + " - " + branch_name_base
} }
display_name = currentBuild.displayName display_name = currentBuild.displayName
mvn_initial("versions:set -DnewVersion=${version}") mvn_initial "versions:set -DnewVersion=${version}"
} }
} }
return this return this

33
pom.xml
View File

@ -30,7 +30,7 @@
<maven.enforcer.version>3.0.0-M2</maven.enforcer.version> <maven.enforcer.version>3.0.0-M2</maven.enforcer.version>
<dep.check.version>5.2.2</dep.check.version> <dep.check.version>5.2.2</dep.check.version>
<license-maven-plugin.version>3.0</license-maven-plugin.version> <license-maven-plugin.version>3.0</license-maven-plugin.version>
<nexus.repo>http://nexus.locusworks.net</nexus.repo> <nexus.repo>https://nexus.locusworks.net</nexus.repo>
</properties> </properties>
<build> <build>
@ -143,13 +143,13 @@
<dependency> <dependency>
<groupId>net.locusworks</groupId> <groupId>net.locusworks</groupId>
<artifactId>applogger</artifactId> <artifactId>applogger</artifactId>
<version>1.0.3-RELEASE</version> <version>1.0.1-RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.locusworks</groupId> <groupId>net.locusworks</groupId>
<artifactId>crypto</artifactId> <artifactId>crypto</artifactId>
<version>1.0.5-RELEASE</version> <version>1.0.1-RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
@ -346,4 +346,31 @@
</repository> </repository>
</distributionManagement> </distributionManagement>
<repositories>
<repository>
<id>locusworks-public</id>
<name>locusworks-public</name>
<url>${nexus.repo}/repository/locusworks-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>locusworks-public</id>
<url>${nexus.repo}/repository/locusworks-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project> </project>