- Added the configuration for SonarQube analysis on build.apache.org/analysis

- Added Jenkinsfile and jenkins.pom for ASF build automation
This commit is contained in:
Christofer Dutz 2019-01-18 15:36:50 +01:00
parent 93727d8e34
commit 33d5a2179d
3 changed files with 337 additions and 70 deletions

183
Jenkinsfile vendored Normal file
View File

@ -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 "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]</a>"
""",
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 "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BRANCH_NAME}] [${env.BUILD_NUMBER}]</a>"
""",
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"
)
}
}
}
}
}

68
jenkins.pom Normal file
View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>21</version>
</parent>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-jenkins-tools</artifactId>
<version>0.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>IoTDB: Jenkins Tools</name>
<description>Set of helpers to do individual tasks only needed on our Jenkins build.</description>
<profiles>
<!--
This profile is used to deploy all the artifacts in the
'local-snapshots-dir' to Apache's SNAPSHOT repo.
-->
<profile>
<id>deploy-snapshots</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>2.0.0</version>
<configuration>
<fromDir>${project.basedir}/local-snapshots-dir</fromDir>
<includes>**</includes>
<serverId>apache.snapshots.https</serverId>
<url>${distMgmtSnapshotsUrl}</url>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

156
pom.xml
View File

@ -61,14 +61,22 @@
<common.io.version>2.5</common.io.version>
<commons.collections4>4.0</commons.collections4>
<thrift.version>0.9.3</thrift.version>
<!-- URL of the ASF SonarQube server -->
<sonar.host.url>https://builds.apache.org/analysis</sonar.host.url>
<!-- Exclude all generated code -->
<sonar.exclusions>**/generated-sources</sonar.exclusions>
</properties>
<!-- if we claim dependencies in dependencyManagement, then we do not claim
their version in sub-project's pom, but we have to claim themselves again
in sub-projects -->
<!--
if we claim dependencies in dependencyManagement, then we do not claim
their version in sub-project's pom, but we have to claim themselves again
in sub-projects
-->
<dependencyManagement>
<dependencies>
<!-- in the subprojects, you have to claim logback again, because maybe
someone in your dependences uses log4j lib. -->
<!--
in the subprojects, you have to claim logback again, because maybe
someone in your dependences uses log4j lib.
-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
@ -139,18 +147,18 @@
<configuration>
<excludePackageNames>*thrift*</excludePackageNames>
<!--
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.
-->
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.
-->
<notimestamp>true</notimestamp>
<!--Don't fail the build, just because there were issues in the JavaDoc generation.-->
<failOnError>false</failOnError>
</configuration>
</plugin>
<!--
We need to increase the memory available to tests as we were
getting out-of-memory errors when building on windows machines.
-->
We need to increase the memory available to tests as we were
getting out-of-memory errors when building on windows machines.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -158,14 +166,22 @@
<argLine>-Xmx512m</argLine>
</configuration>
</plugin>
<!--
Plugin for doing the code analysis.
-->
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.6.0.1398</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!--
Strange things 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.
-->
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.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
@ -202,14 +218,14 @@
</dependencies>
</plugin>
<!--
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.
-->
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.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
@ -297,45 +313,45 @@
</executions>
</plugin>
<!--
Check if all files contain Apache headers in them.
Ignore this plugin, we use license-maven-plugin to check apache header.
-->
Check if all files contain Apache headers in them.
Ignore this plugin, we use license-maven-plugin to check apache header.
-->
<!-- <plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<executions>
<execution>
<id>license-check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
Should be enabled as soon as the headers are in position
<skip>true</skip>
<excludes>
Git related files
<exclude>**/.git/**</exclude>
<exclude>**/.gitignore</exclude>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<executions>
<execution>
<id>license-check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
Should be enabled as soon as the headers are in position
<skip>true</skip>
<excludes>
Git related files
<exclude>**/.git/**</exclude>
<exclude>**/.gitignore</exclude>
Maven related files
<exclude>**/target/**</exclude>
Maven related files
<exclude>**/target/**</exclude>
Eclipse related files
<exclude>**/.project</exclude>
<exclude>**/.settings/**</exclude>
<exclude>**/.classpath</exclude>
Eclipse related files
<exclude>**/.project</exclude>
<exclude>**/.settings/**</exclude>
<exclude>**/.classpath</exclude>
IntelliJ related files
<exclude>**/.idea/**</exclude>
<exclude>**/*.iml</exclude>
Runtime log
<exclude>**/*.log</exclude>
</excludes>
</configuration>
</plugin> -->
IntelliJ related files
<exclude>**/.idea/**</exclude>
<exclude>**/*.iml</exclude>
Runtime log
<exclude>**/*.log</exclude>
</excludes>
</configuration>
</plugin> -->
<!--use `mvn cobertura:cobertura` -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
@ -380,8 +396,8 @@
</executions>
</plugin>
<!--
Generate the legally required text files in the jars
-->
Generate the legally required text files in the jars
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
@ -408,9 +424,9 @@
</build>
<profiles>
<!--
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.
-->
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.
-->
<profile>
<id>windows</id>
<activation>
@ -458,14 +474,14 @@
</properties>
</profile>
<!--
Self activating profile, that activates itself as soon as a "src/main/thrift" directory is found.
The different plugins here download the thrift executable matching the current os, make that
executable (on mac and unix/linux) and run the code generation.
Self activating profile, that activates itself as soon as a "src/main/thrift" directory is found.
The different plugins here download the thrift executable matching the current os, make that
executable (on mac and unix/linux) and run the code generation.
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
-->
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
-->
<profile>
<id>thrift-generation</id>
<activation>