Verified Commit 30acfb5b authored by Martin Raifer's avatar Martin Raifer
Browse files

add jenkinsfile for CI

parent c8ae8095
pipeline {
agent {label 'master'}
environment {
RELEASE_REGEX = /^([0-9]+(\.[0-9]+)*)(-(RC|beta-|alpha-)[0-9]+)?$/
RELEASE_DEPLOY = false
SNAPSHOT_DEPLOY = false
VERSION = sh(returnStdout: true, script: 'mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -Ev "(^\\[|Download\\w+)"').trim()
MAVEN_TEST_OPTIONS = ' '
}
stages {
stage ('Build and Test') {
steps {
script {
env.MAVEN_HOME = '/usr/share/maven'
author = sh(returnStdout: true, script: 'git show -s --pretty=%an')
echo author
commiti= sh(returnStdout: true, script: 'git log -1')
echo commiti
reponame=sh(returnStdout: true, script: 'basename `git remote get-url origin` .git').trim()
echo reponame
gittiid=sh(returnStdout: true, script: 'git describe --tags --long --always').trim()
echo gittiid
echo env.BRANCH_NAME
echo env.BUILD_NUMBER
echo env.TAG_NAME
if(!(VERSION ==~ RELEASE_REGEX || VERSION ==~ /.*-SNAPSHOT$/)) {
echo 'Version:'
echo VERSION
error 'The version declaration is invalid. It is neither a release nor a snapshot. Mabe some error while fetching it using maven.'
}
}
script {
server = Artifactory.server 'HeiGIT Repo'
rtMaven = Artifactory.newMavenBuild()
rtMaven.resolver server: server, releaseRepo: 'main', snapshotRepo: 'main'
rtMaven.deployer server: server, releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local'
rtMaven.deployer.deployArtifacts = false
withCredentials([string(credentialsId: 'gpg-signing-key-passphrase', variable: 'PASSPHRASE')]) {
buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean compile javadoc:jar source:jar install -P sign,git,withDep -Dmaven.repo.local=.m2 $MAVEN_TEST_OPTIONS -Dgpg.passphrase=$PASSPHRASE'
}
}
}
post {
failure {
rocketSend channel: 'jenkinsohsome', emoji: ':sob:' , message: "$reponame-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}. Review the code!" , rawMessage: true
}
}
}
stage ('Reports and Statistics') {
steps {
script {
// jacoco
report_dir="/srv/reports/" + reponame + "/" + VERSION + "_" + env.BRANCH_NAME + "/" + env.BUILD_NUMBER + "_" +gittiid+"/jacoco/"
rtMaven.run pom: 'pom.xml', goals: 'clean verify -Pjacoco -Dmaven.repo.local=.m2 $MAVEN_TEST_OPTIONS'
jacoco(
execPattern : 'target/jacoco.exec',
classPattern : 'target/classes',
sourcePattern : 'src/main/java',
inclusionPattern : '/org/heigit/**'
)
sh "mkdir -p $report_dir && rm -Rf $report_dir* && find . -path '*/target/site/jacoco' -exec cp -R --parents {} $report_dir \\; && find $report_dir -path '*/target/site/jacoco' | while read line; do echo \$line; neu=\${line/target\\/site\\/jacoco/} ; mv \$line/* \$neu ; done && find $report_dir -type d -empty -delete"
// infer
if(env.BRANCH_NAME ==~ /(^master$)/) {
report_dir="/srv/reports/" + reponame + "/" + VERSION + "_" + env.BRANCH_NAME + "/" + env.BUILD_NUMBER + "_" +gittiid+"/infer/"
sh "mvn clean"
sh "infer run --pmd-xml -r -- mvn compile"
sh "mkdir -p $report_dir && rm -Rf $report_dir* && cp -R ./infer-out/* $report_dir"
}
// warnings plugin
rtMaven.run pom: 'pom.xml', goals: '--batch-mode -V -e compile checkstyle:checkstyle pmd:pmd pmd:cpd com.github.spotbugs:spotbugs-maven-plugin:3.1.7:spotbugs -Dmaven.repo.local=.m2'
recordIssues enabledForFailure: true, tools: [mavenConsole(), java(), javaDoc()]
recordIssues enabledForFailure: true, tool: checkStyle()
recordIssues enabledForFailure: true, tool: spotBugs()
recordIssues enabledForFailure: true, tool: cpd(pattern: '**/target/cpd.xml')
recordIssues enabledForFailure: true, tool: pmdParser(pattern: '**/target/pmd.xml')
recordIssues enabledForFailure: true, tool: pmdParser(pattern: '**/infer-out/report.xml', id: 'infer')
}
}
post {
failure {
rocketSend channel: 'jenkinsohsome', message: "Reporting of $reponame-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
}
}
stage ('Encourage') {
when {
expression {
if(currentBuild.number > 1) {
datepre=new Date(currentBuild.previousBuild.rawBuild.getStartTimeInMillis()).clearTime()
echo datepre.format( 'yyyyMMdd' )
datenow=new Date(currentBuild.rawBuild.getStartTimeInMillis()).clearTime()
echo datenow.format( 'yyyyMMdd' )
return datepre.numberAwareCompareTo(datenow)<0
}
return false
}
}
steps {
rocketSend channel: 'jenkinsohsome', message: "Hey, this is just your daily notice that Jenkins is still working for you on $reponame Branch ${env.BRANCH_NAME}! Happy and for free! Keep it up!" , rawMessage: true
}
post {
failure {
rocketSend channel: 'jenkinsohsome', emoji: ':wink:' , message: "Reporting of $reponame-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
}
}
stage ('Report Status Change') {
when {
expression {
return ((currentBuild.number > 1) && (currentBuild.getPreviousBuild().result == 'FAILURE'))
}
}
steps {
rocketSend channel: 'jenkinsohsome', message: "We had some problems, but we are BACK TO NORMAL! Nice debugging: $reponame-build-nr. ${env.BUILD_NUMBER} *succeeded* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
post {
failure {
rocketSend channel: 'jenkinsohsome', message: "Reporting of $reponame-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
}
}
}
}
  • jenkinsci/branch: The Jenkins CI build failed - Details

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment