From 33d5a2179d9e70355378c7a0787c1a8c783c88ad Mon Sep 17 00:00:00 2001 From: Christofer Dutz Date: Fri, 18 Jan 2019 15:36:50 +0100 Subject: [PATCH] - Added the configuration for SonarQube analysis on build.apache.org/analysis - Added Jenkinsfile and jenkins.pom for ASF build automation --- Jenkinsfile | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++ jenkins.pom | 68 +++++++++++++++++++ pom.xml | 156 ++++++++++++++++++++++++-------------------- 3 files changed, 337 insertions(+), 70 deletions(-) create mode 100644 Jenkinsfile create mode 100644 jenkins.pom diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000000..10f36876b69 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,183 @@ +#!groovy + +/** + * Copyright © 2019 Apache IoTDB(incubating) (dev@iotdb.apache.org) + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +pipeline { + + agent { + node { + label 'ubuntu' + } + } + + environment { + // Testfails will be handled by the jenkins junit steps and mark the build as unstable. + MVN_TEST_FAIL_IGNORE = '-Dmaven.test.failure.ignore=true' + } + + tools { + maven 'Maven 3 (latest)' + jdk 'JDK 1.8 (latest)' + } + + options { + timeout(time: 1, unit: 'HOURS') + // When we have test-fails e.g. we don't need to run the remaining steps + skipStagesAfterUnstable() + } + + stages { + stage('Initialization') { + steps { + echo 'Building Branch: ' + env.BRANCH_NAME + echo 'Using PATH = ' + env.PATH + } + } + + stage('Checkout') { + steps { + echo 'Checking out branch ' + env.BRANCH_NAME + checkout scm + } + } + + stage('Build (not master)') { + when { + expression { + env.BRANCH_NAME != 'master' + } + } + steps { + echo 'Building' + sh 'mvn ${MVN_TEST_FAIL_IGNORE} ${MVN_LOCAL_REPO_OPT} clean install' + } + post { + always { + junit(testResults: '**/surefire-reports/*.xml', allowEmptyResults: true) + junit(testResults: '**/failsafe-reports/*.xml', allowEmptyResults: true) + } + } + } + + stage('Build') { + when { + branch 'master' + } + steps { + echo 'Building' + // We'll deploy to a relative directory so we can + // deploy new versions only if the entrie build succeeds + sh 'mvn ${MVN_TEST_FAIL_IGNORE} -DaltDeploymentRepository=snapshot-repo::default::file:./local-snapshots-dir clean deploy' + } + post { + always { + junit(testResults: '**/surefire-reports/*.xml', allowEmptyResults: true) + junit(testResults: '**/failsafe-reports/*.xml', allowEmptyResults: true) + } + } + } + + stage('Code Quality') { + when { + branch 'master' + } + steps { + echo 'Checking Code Quality' + withSonarQubeEnv('ASF Sonar Analysis') { + sh 'mvn sonar:sonar' + } + } + } + + stage('Deploy') { + when { + branch 'master' + } + steps { + echo 'Deploying' + // Deploy the artifacts using the wagon-maven-plugin. + sh 'mvn -f jenkins.pom -X -P deploy-snapshots wagon:upload' + } + } + + stage('Cleanup') { + steps { + echo 'Cleaning up the workspace' + deleteDir() + } + } + } + + // Send out notifications on unsuccessful builds. + post { + // If this build failed, send an email to the list. + failure { + script { + if(env.BRANCH_NAME == "master") { + emailext( + subject: "[BUILD-FAILURE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'", + body: """ +BUILD-FAILURE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]': + +Check console output at "${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]" +""", + to: "dev@iotdb.apache.org" + ) + } + } + } + + // If this build didn't fail, but there were failing tests, send an email to the list. + unstable { + script { + if(env.BRANCH_NAME == "master") { + emailext( + subject: "[BUILD-UNSTABLE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'", + body: """ +BUILD-UNSTABLE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]': + +Check console output at "${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]" +""", + to: "dev@iotdb.apache.org" + ) + } + } + } + + // Send an email, if the last build was not successful and this one is. + success { + script { + if ((env.BRANCH_NAME == "master") && (currentBuild.previousBuild != null) && (currentBuild.previousBuild.result != 'SUCCESS')) { + emailext ( + subject: "[BUILD-STABLE]: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]'", + body: """ +BUILD-STABLE: Job '${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]': + +Is back to normal. +""", + to: "dev@iotdb.apache.org" + ) + } + } + } + } + +} \ No newline at end of file diff --git a/jenkins.pom b/jenkins.pom new file mode 100644 index 00000000000..5227ebb5c65 --- /dev/null +++ b/jenkins.pom @@ -0,0 +1,68 @@ + + + + + 4.0.0 + + + org.apache + apache + 21 + + + org.apache.iotdb + iotdb-jenkins-tools + 0.2.0-SNAPSHOT + pom + + IoTDB: Jenkins Tools + Set of helpers to do individual tasks only needed on our Jenkins build. + + + + + deploy-snapshots + + + + org.codehaus.mojo + wagon-maven-plugin + 2.0.0 + + ${project.basedir}/local-snapshots-dir + ** + apache.snapshots.https + ${distMgmtSnapshotsUrl} + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3a658aeb2d0..118be21201f 100644 --- a/pom.xml +++ b/pom.xml @@ -61,14 +61,22 @@ 2.5 4.0 0.9.3 + + https://builds.apache.org/analysis + + **/generated-sources - + - + ch.qos.logback logback-classic @@ -139,18 +147,18 @@ *thrift* + This will suppress the generation of a hidden timestamp at the top of each generated html page + and hopefully let the site generation nod to too big updates every time. + --> true false + We need to increase the memory available to tests as we were + getting out-of-memory errors when building on windows machines. + --> org.apache.maven.plugins maven-surefire-plugin @@ -158,14 +166,22 @@ -Xmx512m + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.6.0.1398 + + Strange xthings usually happen if you run with a too low Java version. + This plugin not only checks the minimum java version of 1.8, but also + checks all dependencies (and transitive dependencies) for reported CVEs. + --> org.apache.maven.plugins maven-enforcer-plugin @@ -202,14 +218,14 @@ + Even if Maven transitively pulls in dependencies, relying on these can + quite often cause hard to find problems. So it's a good practice to make + sure everything directly required is also directly added as a dependency. + On the other side adding unused dependency only over-complicates the + the dependency graph, so the maven-dependency-plugin checks we depend on + what we need and only that and that runtime dependencies are correctly + imported with runtime scope. + --> org.apache.maven.plugins maven-dependency-plugin @@ -297,45 +313,45 @@ + Check if all files contain Apache headers in them. + Ignore this plugin, we use license-maven-plugin to check apache header. + --> + IntelliJ related files + **/.idea/** + **/*.iml + Runtime log + **/*.log + + + --> org.codehaus.mojo @@ -380,8 +396,8 @@ + Generate the legally required text files in the jars + --> org.apache.maven.plugins maven-remote-resources-plugin @@ -408,9 +424,9 @@ + A set of profiles defining the different properties needed to download and run thrift + They are automatically activated depending on the OS you are using. + --> windows @@ -458,14 +474,14 @@ + Note to the Download: The download-maven-plugin checks if a resource is previously downloaded + and only downloads each file once. It caches downloaded files in: + {maven local repo}/.cache/download-maven-plugin + --> thrift-generation