node { try{ stage('Checkout') { checkout scm } // End Checkout stage('Build') { docker.image("registry.nspop.dk/tools/nspbuilder:${NSPBUILDER_TAG}").inside(){ sh "mvn -B -Dmaven.repo.local=m2 clean install" } junit '**/target/surefire-reports/*.xml' jacoco ( changeBuildStatus: true, inclusionPattern: '**/dk/nsp/**/*.*', maximumLineCoverage: '80', minimumLineCoverage: '70' ) } // End Build stage('Archive') { // This step copies all the project produced artifacts into 'artifacts' docker.image("registry.nspop.dk/tools/nspbuilder:${NSPBUILDER_TAG}").inside() { def script = """ mkdir -p artifacts && \ mvn -q \ -Dmaven.repo.local=m2 \ -Dexec.executable='echo' \ -Dexec.args='\${project.groupId} \${project.artifactId} \${project.version} \${project.packaging}' \ exec:exec \ | tee artifacts/artifacts.txt \ | awk '{ grpID=\$1; name=\$2; version=\$3; packaging=\$4; grpFolder=grpID gsub(/[.]/,"/",grpFolder); m2Folder=grpFolder "/" name "/"; system("mkdir -p artifacts/" m2Folder) system("cp -r m2/" m2Folder "*" " artifacts/" m2Folder) }' """ sh script archiveArtifacts artifacts: 'artifacts/**/*', followSymlinks: false sh 'chmod -R 777 artifacts m2' } } // End Archive } finally { stage('Cleanup') { deleteDir() } // End Cleanup if(currentBuild.resultIsWorseOrEqualTo('UNSTABLE')) { slackSend ( channel: 'kit_ci', color: 'bad', message: "${env.JOB_NAME} ${env.BUILD_NUMBER} - Build failed ... (<${env.BUILD_URL}|Open>)", tokenCredentialId: 'Slack-Token' ) } // End Fail notification if(currentBuild.resultIsBetterOrEqualTo('SUCCESS') && currentBuild.previousBuild != null && currentBuild.previousBuild.resultIsWorseOrEqualTo('UNSTABLE')) { slackSend ( channel: 'kit_ci', color: 'good', message: "${env.JOB_NAME} ${env.BUILD_NUMBER} - Build succeeded. I will shut up until next failure! ... (<${env.BUILD_URL}|Open>)", tokenCredentialId: 'Slack-Token' ) } // End success notification } // End try-finally } // End node