Commit 34bc8b9d authored by Martin Raifer's avatar Martin Raifer
Browse files

Merge branch 'jenkinsfile-minor-fix' into 'master'

Jenkinsfile minor fix and clean up

See merge request !2
parents 702a778b fb101f07
pipeline {
agent {label 'master'}
agent {label 'main'}
environment {
REPO_NAME = sh(returnStdout: true, script: 'basename `git remote get-url origin` .git').trim()
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()
LATEST_AUTHOR = sh(returnStdout: true, script: 'git show -s --pretty=%an').trim()
LATEST_COMMIT_ID = sh(returnStdout: true, script: 'git describe --tags --long --always').trim()
MAVEN_TEST_OPTIONS = ' '
INFER_BRANCH_REGEX = /(^master$)/
SNAPSHOT_BRANCH_REGEX = /(^master$)/
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 {
......@@ -16,26 +21,18 @@ pipeline {
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 REPO_NAME
echo LATEST_AUTHOR
echo LATEST_COMMIT_ID
echo env.BRANCH_NAME
echo env.BUILD_NUMBER
echo env.TAG_NAME
if(!(VERSION ==~ RELEASE_REGEX || VERSION ==~ /.*-SNAPSHOT$/)) {
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.'
error 'The version declaration is invalid. It is neither a release nor a snapshot. Maybe an error occured while fetching the parent pom using maven?'
}
}
script {
......@@ -53,32 +50,37 @@ pipeline {
}
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
rocketSend channel: 'jenkinsohsome', emoji: ':sob:' , message: "*${REPO_NAME}*-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${LATEST_AUTHOR}. Review the code!" , rawMessage: true
}
}
}
// START CUSTOM oshdb-extractor
// Deployment and Javadoc not necessary here
// END CUSTOM oshdb-extractor
stage ('Reports and Statistics') {
steps {
script {
report_basedir = "/srv/reports/${REPO_NAME}/${VERSION}_${env.BRANCH_NAME}/${env.BUILD_NUMBER}_${LATEST_COMMIT_ID}"
// jacoco
report_dir="/srv/reports/" + reponame + "/" + VERSION + "_" + env.BRANCH_NAME + "/" + env.BUILD_NUMBER + "_" +gittiid+"/jacoco/"
report_dir = report_basedir + "/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',
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"
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/"
if (env.BRANCH_NAME ==~ INFER_BRANCH_REGEX) {
report_dir = report_basedir + "/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"
sh "mkdir -p ${report_dir} && rm -Rf ${report_dir}* && cp -R ./infer-out/* ${report_dir}"
}
// warnings plugin
......@@ -94,7 +96,34 @@ pipeline {
}
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
rocketSend channel: 'jenkinsohsome', emoji: ':disappointed:', message: "Reporting of *${REPO_NAME}*-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${LATEST_AUTHOR}." , rawMessage: true
}
}
}
stage ('Check Dependencies') {
when {
expression {
if (currentBuild.number > 1) {
month_pre = new Date(currentBuild.previousBuild.rawBuild.getStartTimeInMillis())[Calendar.MONTH]
echo month_pre.toString()
month_now = new Date(currentBuild.rawBuild.getStartTimeInMillis())[Calendar.MONTH]
echo month_now.toString()
return month_pre != month_now
}
return false
}
}
steps {
script {
update_notify = sh(returnStdout: true, script: 'mvn versions:display-dependency-updates | grep -Pzo "(?s)The following dependencies.*\\n.* \\n"').trim()
echo update_notify
}
rocketSend channel: 'jenkinsohsome', emoji: ':wave:' , message: "Check your dependencies in *${REPO_NAME}*. You might have updates: ${update_notify}" , rawMessage: true
}
post {
failure {
rocketSend channel: 'jenkinsohsome', emoji: ':disappointed:' , message: "Checking for updates in *${REPO_NAME}*-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${LATEST_AUTHOR}." , rawMessage: true
}
}
}
......@@ -102,22 +131,22 @@ pipeline {
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
if (currentBuild.number > 1) {
date_pre = new Date(currentBuild.previousBuild.rawBuild.getStartTimeInMillis()).clearTime()
echo date_pre.format( 'yyyyMMdd' )
date_now = new Date(currentBuild.rawBuild.getStartTimeInMillis()).clearTime()
echo date_now.format( 'yyyyMMdd' )
return date_pre.numberAwareCompareTo(date_now)<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
rocketSend channel: 'jenkinsohsome', emoji: ':wink:', message: "Hey, this is just your daily notice that Jenkins is still working for you on *${REPO_NAME}* 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
rocketSend channel: 'jenkinsohsome', emoji: ':disappointed:', message: "Reporting of *${REPO_NAME}*-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${LATEST_AUTHOR}." , rawMessage: true
}
}
}
......@@ -129,11 +158,11 @@ pipeline {
}
}
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
rocketSend channel: 'jenkinsohsome', emoji: ':sunglasses:', message: "We had some problems, but we are BACK TO NORMAL! Nice debugging: *${REPO_NAME}*-build-nr. ${env.BUILD_NUMBER} *succeeded* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${LATEST_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
rocketSend channel: 'jenkinsohsome', emoji: ':disappointed:', message: "Reporting of *${REPO_NAME}*-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${LATEST_AUTHOR}." , rawMessage: true
}
}
}
......
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