diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..c78b3ac --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,97 @@ +pipeline { + agent none + + stages { + stage('Maven Build') { + agent { + docker 'maven:3.8.3-openjdk-11' + } + stages { + stage('Build project') { + steps { + withCredentials([usernamePassword(credentialsId: 'jenkins_nexus', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASSWORD')]) { + sh 'mvn clean install -B -s settings.xml' + } + + } + } + stage('Deploy Maven Artifact') { + when { + anyOf { + branch 'master'; branch 'dev' + } + } + steps { + withCredentials([usernamePassword(credentialsId: 'jenkins_nexus', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASSWORD')]) { + sh 'mvn deploy -Dnexus.user=${USERNAME} -Dnexus.password=${PASSWORD} -B -s settings.xml' + } + } + } + } + } + } + post { + failure { + node(null) { + script { + if(BRANCH_NAME == 'master' || BRANCH_NAME == 'dev') { + emailext( + to: "notifications@nclazz.de", + from: "jenkins@nclazz.de", + subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} failed", + body: """ + There is a build failure in ${env.JOB_NAME}. + Build: ${env.BUILD_URL} + Logs: ${env.BUILD_URL}console + Changes: ${env.BUILD_URL}changes + -- + """ + ) + } + } + } + } + unstable { + node(null) { + script { + if(BRANCH_NAME == 'master' || BRANCH_NAME == 'dev') { + emailext( + to: "notifications@nclazz.de", + from: "jenkins@nclazz.de", + subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} unstable", + body: """ + Some tests have failed in ${env.JOB_NAME}. + Build: ${env.BUILD_URL} + Logs: ${env.BUILD_URL}console + Changes: ${env.BUILD_URL}changes + -- + """ + ) + } + } + } + } + fixed { + node(null) { + script { + if(BRANCH_NAME == 'master' || BRANCH_NAME == 'dev') { + emailext( + to: "notifications@nclazz.de", + from: "jenkins@nclazz.de", + subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} fixed", + body: """ + The build ${env.JOB_NAME} completed successfully and is back to normal. + + Build: ${env.BUILD_URL} + Logs: ${env.BUILD_URL}console + Changes: ${env.BUILD_URL}changes + -- + """ + ) + } + } + } + + } + } +} \ No newline at end of file diff --git a/settings.xml b/settings.xml new file mode 100644 index 0000000..189dd98 --- /dev/null +++ b/settings.xml @@ -0,0 +1,25 @@ + + + + + + + + nexus.nclazz.de + NClazz Nexus Repository Manager + https://nexus.nclazz.de/repository/maven-public + * + + + + + nexus.nclazz.de + ${NEXUS_USER} + ${NEXUS_PASSWORD} + + + + + + \ No newline at end of file