Commit 33fea542 authored by Moritz Schott's avatar Moritz Schott
Browse files

Update Jenkinsfile

parent 82bc7199
pipeline {
/*tried slave dockers but only had disadvantages
agent {
docker{
image 'maven:3-jdk-8'
args '-v /root/.m2:/root/.m2'
}
}
*/
agent any
agent {label 'master'}
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
}
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.addProperty("deployer", "jenkinsOhsome")
rtMaven.deployer.deployArtifacts = false
env.MAVEN_HOME = '/usr/share/maven'
buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean install -Dmaven.repo.local=.m2'
}
script {
buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean compile javadoc:jar source:jar install -Dmaven.repo.local=.m2'
}
}
post{
post {
failure {
rocketSend channel: 'jenkinsohsome', emoji: ':sob:' , message: "examples-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 ('deploy'){
when {
expression {
return env.BRANCH_NAME ==~ /(^[0-9]+$)|(^(([0-9]+)(\.))+([0-9]+)?$)|(^master$)/
}
}
stage ('Reports and Statistics') {
steps {
script {
rtMaven.deployer.deployArtifacts buildInfo
server.publishBuildInfo buildInfo
projver=sh(returnStdout: true, script: 'mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -Ev "(^\\[|Download\\w+)"').trim()
//warnings plugin
rtMaven.run pom: 'pom.xml', goals: '--batch-mode -V -e checkstyle:checkstyle pmd:pmd pmd:cpd findbugs:findbugs com.github.spotbugs:spotbugs-maven-plugin:3.1.7:spotbugs -Dmaven.repo.local=.m2'
recordIssues enabledForFailure: true, tool: checkStyle()
recordIssues enabledForFailure: true, tool: findBugs()
recordIssues enabledForFailure: true, tool: spotBugs()
recordIssues enabledForFailure: true, tool: cpd(pattern: '**/target/cpd.xml')
recordIssues enabledForFailure: true, tool: pmdParser(pattern: '**/target/pmd.xml')
}
}
post {
failure {
rocketSend channel: 'jenkinsohsome', message: "Deployment of examples-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}. Is Artifactory running?" , rawMessage: true
rocketSend channel: 'jenkinsohsome', message: "Reporting of examples-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 ('publish Javadoc'){
stage ('Check Dependencies') {
when {
expression {
return env.BRANCH_NAME ==~ /(^[0-9]+$)|(^(([0-9]+)(\.))+([0-9]+)?$)|(^master$)/
if(currentBuild.number > 1) {
monthpre=new Date(currentBuild.previousBuild.rawBuild.getStartTimeInMillis())[Calendar.MONTH]
echo monthpre.toString()
monthnow=new Date(currentBuild.rawBuild.getStartTimeInMillis())[Calendar.MONTH]
echo monthnow.toString()
return monthpre!=monthnow
}
return false
}
}
steps {
script{
//load dependencies to artifactory
rtMaven.run pom: 'pom.xml', goals: 'org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version -Dmaven.repo.local=.m2'
projver=sh(returnStdout: true, script: 'mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -Ev "(^\\[|Download\\w+:)"').trim()
javadc_dir="/srv/javadoc/java/" + reponame + "/" + projver + "/"
echo javadc_dir
rtMaven.run pom: 'pom.xml', goals: 'clean javadoc:javadoc -Dadditionalparam=-Xdoclint:none -Dmaven.repo.local=.m2'
sh "echo $javadc_dir"
//make shure jenkins uses bash not dash!
sh "mkdir -p $javadc_dir && rm -Rf $javadc_dir* && find . -path '*/target/site/apidocs' -exec cp -R --parents {} $javadc_dir \\; && find $javadc_dir -path '*/target/site/apidocs' | while read line; do echo \$line; neu=\${line/target\\/site\\/apidocs/} ; mv \$line/* \$neu ; done && find $javadc_dir -type d -empty -delete"
}
script{
javadc_dir=javadc_dir + "aggregated/"
rtMaven.run pom: 'pom.xml', goals: 'clean javadoc:aggregate -Dadditionalparam=-Xdoclint:none -Dmaven.repo.local=.m2'
sh "mkdir -p $javadc_dir && rm -Rf $javadc_dir* && find . -path './target/site/apidocs' -exec cp -R --parents {} $javadc_dir \\; && find $javadc_dir -path '*/target/site/apidocs' | while read line; do echo \$line; neu=\${line/target\\/site\\/apidocs/} ; mv \$line/* \$neu ; done && find $javadc_dir -type d -empty -delete"
script {
updatenotify=sh(returnStdout: true, script: 'mvn versions:display-dependency-updates | grep -Pzo "(?s)The following dependencies.*\\n.* \\n"').trim()
echo updatenotify
}
rocketSend channel: 'jenkinsohsome', emoji: ':wave:' , message: "You might have updates in your dependecies for the examples: ${updatenotify}" , rawMessage: true
}
post {
failure {
rocketSend channel: 'jenkinsohsome', message: "Deployment of javadoc examples-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: "Checking for updates in examples-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 {
stage ('Encourage') {
when {
expression {
if(currentBuild.number > 1){
if(currentBuild.number > 1) {
datepre=new Date(currentBuild.previousBuild.rawBuild.getStartTimeInMillis()).clearTime()
echo datepre.format( 'yyyyMMdd' )
datenow=new Date(currentBuild.rawBuild.getStartTimeInMillis()).clearTime()
......@@ -112,30 +102,29 @@ pipeline {
}
}
steps {
rocketSend channel: 'jenkinsohsome', message: "Hey, this is just your daily notice that Jenkins is still working for you! Happy and for free! Keep it up!" , rawMessage: true
rocketSend channel: 'jenkinsohsome', message: "Hey, this is just your daily notice that Jenkins is still working for you on OSHDB-Examples-Branch ${env.BRANCH_NAME}! Happy and for free! Keep it up!" , rawMessage: true
}
post {
failure {
rocketSend channel: 'jenkinsohsome', emoji: ':wink:' , message: "Reporting of oshdb-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: ':wink:' , message: "Reporting of examples-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'){
stage ('Report Status Change') {
when {
expression {
return ((currentBuild.number > 1) && (currentBuild.getPreviousBuild().result == 'FAILURE'))
}
}
steps {
rocketSend channel: 'jenkinsohsome', message: "We had some problems, bu we are BACK TO NORMAL! Nice debugging: oshdb-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', message: "We had some problems, but we are BACK TO NORMAL! Nice debugging: oshdb-examples-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 oshdb-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', message: "Reporting of examples-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
}
}
}
}
}
\ No newline at end of file
}
}
\ No newline at end of file
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