Fixed Jenkinsfile and pom
All checks were successful
Locusworks Team/crypto/pipeline/head This commit looks good
All checks were successful
Locusworks Team/crypto/pipeline/head This commit looks good
This commit is contained in:
136
Jenkinsfile
vendored
136
Jenkinsfile
vendored
@ -1,5 +1,16 @@
|
||||
#!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()
|
||||
|
||||
@ -23,7 +34,8 @@ def init() {
|
||||
build_url = env.BUILD_URL
|
||||
job_name = "${env.JOB_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
|
||||
try {
|
||||
@ -31,52 +43,44 @@ def init() {
|
||||
if (branch_name.indexOf('release/')==0) build_type='release'
|
||||
if (branch_name.indexOf('feature/')==0) build_type='feature'
|
||||
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('hotfix/')==0) build_type='hotfix'
|
||||
if (branch_name.indexOf('bugfix/')==0) build_type='bugfix'
|
||||
|
||||
switch(build_type) {
|
||||
case ~/feature/:
|
||||
case ~/hotfix/:
|
||||
case ~/bugfix/:
|
||||
case ~/master/:
|
||||
case ~/develop/:
|
||||
CommonBuild();
|
||||
break;
|
||||
case ~/release/:
|
||||
CommonBuild();
|
||||
Deploy();
|
||||
break;
|
||||
default:
|
||||
throw "unsupported branch type: ${branch_name}"
|
||||
// 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
|
||||
}
|
||||
|
||||
if (branch_name.indexOf('develop')==0) {
|
||||
node('master') {
|
||||
Deploy();
|
||||
}
|
||||
} else if (branch_name.indexOf('release/')==0) {
|
||||
node('master') {
|
||||
Deploy();
|
||||
}
|
||||
}
|
||||
|
||||
node('master') {
|
||||
set_result('SUCCESS')
|
||||
set_result('SUCCESS')
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
node() {
|
||||
set_result('FAILURE')
|
||||
set_result('FAILURE')
|
||||
}
|
||||
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() {
|
||||
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])
|
||||
}
|
||||
}
|
||||
@ -92,10 +96,8 @@ def Initialize() {
|
||||
}
|
||||
|
||||
def Deploy() {
|
||||
node('master') {
|
||||
stage ('deploy') {
|
||||
mvn_alt("deploy -DskipTests=true -Dbuild.number=${build_number} -Dbuild.revision=${git_commit}")
|
||||
}
|
||||
stage ('deploy') {
|
||||
mvn "deploy -DskipTests=true -Dbuild.number=${build_number} -Dbuild.revision=${git_commit}"
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,17 +107,19 @@ def getSha1() {
|
||||
return sha1
|
||||
}
|
||||
|
||||
def mvn_initial(args) {
|
||||
mvn_alt(args)
|
||||
def mvn(args) {
|
||||
withMaven(
|
||||
maven: 'maven-3.6.1',
|
||||
globalMavenSettingsConfig: 'locusworks-settings'
|
||||
) {
|
||||
|
||||
sh "mvn ${args}"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
def mvn_alt(args) {
|
||||
// add maven tools to path before calling maven
|
||||
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 mvn_initial(args) {
|
||||
mvn(args)
|
||||
}
|
||||
|
||||
def set_result(status) {
|
||||
@ -130,10 +134,13 @@ def set_result(status) {
|
||||
} else {
|
||||
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) {
|
||||
echo "notify bitbucket, state = $state, commit: ${git_commit}"
|
||||
}
|
||||
|
||||
def print_vars() {
|
||||
@ -146,34 +153,33 @@ def print_vars() {
|
||||
echo "display_name = ${currentBuild.displayName}"
|
||||
echo "version = ${version}"
|
||||
echo "git_commit = ${git_commit}"
|
||||
|
||||
}
|
||||
|
||||
def SetVersion( v ) {
|
||||
stage ('set version') {
|
||||
echo "set version ${v}"
|
||||
branch_name_base = (branch_name =~ /([^\/]+$)/)[0][0]
|
||||
|
||||
switch(build_type) {
|
||||
case ~/develop/:
|
||||
version = build_number + '-SNAPSHOT'
|
||||
currentBuild.displayName = version
|
||||
break;
|
||||
case ~/release/:
|
||||
// for release branches, where the branch is named "release/1.2.3",
|
||||
// derive the version and display name derive from the numeric suffix and append the build number
|
||||
// 3.2.1.100
|
||||
version = branch_name_base + '.' + build_number + '-RELEASE'
|
||||
currentBuild.displayName = version
|
||||
break;
|
||||
default:
|
||||
// for all other branches the version number is 0 with an appended build number
|
||||
// and for the display name use the jenkins default #n and add the branch name
|
||||
version = branch_name_base + "." + build_number
|
||||
currentBuild.displayName = "#" + build_number + " - " + branch_name_base
|
||||
if ( v == 'release' ) {
|
||||
// for release branches, where the branch is named "release/1.2.3",
|
||||
// derive the version and display name derive from the numeric suffix and append the build number
|
||||
// 3.2.1.100
|
||||
version = branch_name_base + "." + build_number + "-RELEASE";
|
||||
//version = branch_name.substring('release/'.length()) + "." + build_number
|
||||
currentBuild.displayName = version
|
||||
} else if (v == 'develop') {
|
||||
version = branch_name_base + "." + build_number + "-SNAPSHOT";
|
||||
currentBuild.displayName = version
|
||||
} else {
|
||||
// for all other branches the version number is 0 with an appended build number
|
||||
// and for the display name use the jenkins default #n and add the branch name
|
||||
// #101 - feature/user/foo
|
||||
//version = '0.' + build_number
|
||||
version = branch_name_base + "." + build_number
|
||||
currentBuild.displayName = "#" + build_number + " - " + branch_name_base
|
||||
}
|
||||
|
||||
display_name = currentBuild.displayName
|
||||
mvn_initial("versions:set -DnewVersion=${version}")
|
||||
mvn_initial "versions:set -DnewVersion=${version}"
|
||||
}
|
||||
}
|
||||
|
||||
|
33
pom.xml
33
pom.xml
@ -15,14 +15,14 @@
|
||||
</organization>
|
||||
|
||||
<scm>
|
||||
<url>git@gitea.locusworks.net:Locusworks/pseudo-bot.git</url>
|
||||
<url>git@bitbucket.org:locus2k/crypto.git</url>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<nexus.repo>http://nexus.locusworks.net</nexus.repo>
|
||||
<license-maven-plugin.version>3.0</license-maven-plugin.version>
|
||||
<nexus.repo>https://nexus.locusworks.net</nexus.repo>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@ -108,7 +108,7 @@
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.13</version>
|
||||
<version>1.14</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
@ -139,5 +139,32 @@
|
||||
</repository>
|
||||
</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>
|
Reference in New Issue
Block a user